aspose file tools*
The moose likes Java in General and the fly likes run executable in java.lang.Runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "run executable in java.lang.Runtime" Watch "run executable in java.lang.Runtime" New topic
Author

run executable in java.lang.Runtime

Cyborg Terminator
Greenhorn

Joined: Oct 21, 2003
Posts: 1
I am trying to execute a /bin/bash shell program in java.lang.Runtime with no avail.
Is this right?

The third member of the String array is the name of the program to be executed
and its input parameters.


T800XXX2003
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Well I can give you an example for Windows and you can try something similar.
Runtime.getRuntime().exec("cmd /K start run.bat");
The /K is a parameter for the cmd command and you can look it up in windows help.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Greg Donahue
Greenhorn

Joined: Oct 07, 2003
Posts: 24
Hi there.
That looks right, but maybe the process is being interrupted? Try:
Process p = Runtime.getRuntime().exec(//Your String array here);
try { p.waitFor(); }
catch (InterruptedException ie) {
System.out.println("Process Interrupted!\n");
ie.printStackTrace(System.out);
}
Also, there may be an STDOUT/STDERR redirection issue. Try grabbing and printing the STDOUT and STDERR of the process within your Java program by doing:
BufferedReader outreader = new BufferedReader(
new InputStreamReader(
p.getInputStream()));
BufferedReader errreader = new BufferedReader(
new InputStreamReader(
p.getErrorStream()));
Hope that helps!
-Greg


vi veri veniversum vivus vici
 
jQuery in Action, 2nd edition
 
subject: run executable in java.lang.Runtime