• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run executable in java.lang.Runtime

 
Cyborg Terminator
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greg Donahue
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic