Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invoke script from Swing - How

Status
Not open for further replies.

chz013

Programmer
Jan 5, 2003
73
0
0
US
Hi
I like to automate a dial-up process from unix
with GUI as the front-end for a user.

Is anyone willing to share on how I could achieve that ?
I'm not sure how in
actionPerformed(ActionEvent e) implementation
that I could invoke this script to dial-up
from unix via modem to a remote access server.

Any help is fully appreciated.
 
Try :

Runtime.getRuntime().exec("/usr/local/bin/myscript");
 
sedj
thanks for the response.
But I still have the problem

else if ("Dial".equals(actionCommand))
{
try {
String[] cmd = {"/usr/bin/bash", "/wongz/scripts/test"};
Runtime.getRuntime().exec(cmd);

} catch ( java.lang.Exception f ) {
System.out.println("dial in actionPerformed fails");
}

}

when I run the GUI, and picked Dial as menuitem,
I still dont see the output.

test
echo Hello Wold !
 
Even when I change to
else if ("Dial".equals(actionCommand))
{
try {

String[] cmd = new String[1];
cmd[0] = "/usr/bin/bash /wongz/scripts/test";

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(cmd);

System.out.println(cmd);

} catch ( java.lang.Exception f ) {
System.out.println("dial in actionPerformed in StatConfigMain");
}

}

I got
dial in actionPerformed in StatConfigMain
dial in actionPerformed in StatConfigMain
bash-2.03#
 
I tried again and I got the following trace:
test file is there but I'm not sure why
it's complaining.

Anyone with any suggestions?
Fully appreciated

================================================
dial in updateCron in StatConfigGUI
java.io.IOException: /usr/bin/bash /wongz/scripts/test: not found
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:54)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:550)
at java.lang.Runtime.exec(Runtime.java:475)
at java.lang.Runtime.exec(Runtime.java:441)
at StatConfigGUI.updateCron(StatConfigGUI.java:348)
at StatConfigGUI$10.actionPerformed(StatConfigGUI.java:197)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1820)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1092)
at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:932)
at java.awt.Component.processMouseEvent(Component.java:5021)
at java.awt.Component.processEvent(Component.java:4818)
at java.awt.Container.processEvent(Container.java:1380)
at java.awt.Component.dispatchEventImpl(Component.java:3526)
at java.awt.Container.dispatchEventImpl(Container.java:1437)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
at java.awt.Container.dispatchEventImpl(Container.java:1423)
at java.awt.Window.dispatchEventImpl(Window.java:1566)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
 
Try this:
Code:
Process proc = rt.exec(&quot;/usr/bin/bash /wongz/scripts/test&quot;);
and you have a directory called /wongz from root, are you sure it's not /usr/wongz or /home/wongz?
 
JavaDude
Thanks for your response

Yeah I'm 100% sure
 
does &quot;which bash&quot; return /usr/bin/bash on the OS console ?

Can you run the command (ie EXACT command) from the console ?

Are you running the test using the same user as you are from the java app ?
 
does &quot;which bash&quot; return /usr/bin/bash on the OS console ?
A- Yes

Can you run the command (ie EXACT command) from the console ?
A- Yes I can.
it shows
Hello World !

Are you running the test using the same user as you are from the java app ?
A- Yes. I'm the root user
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top