This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: run executable in java.lang.Runtime
 
Similar Threads
How to call a build.xml
shell script
What is the use of Runtime.getRuntime()
how to make an exe
Running java program from another java program