File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "run executable in java.lang.Runtime" Watch "run executable in java.lang.Runtime" New topic

run executable in java.lang.Runtime

Cyborg Terminator

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.

Cindy Glass
"The Hood"

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

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");
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(
BufferedReader errreader = new BufferedReader(
new InputStreamReader(
Hope that helps!

vi veri veniversum vivus vici
I agree. Here's the link:
subject: run executable in java.lang.Runtime
It's not a secret anymore!