Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Error while executing shell script from java


Tags:

Hi,
I am trying to execute an unix schell script from Java class using Runtime.execute(). But i am getting exitValue 139 while doing this.
Please find the code snippet:

try{
String scriptName = "test.ksh";
String argParameter = "satish"; // parameter passed to ksh file.
String scriptToBePassed = "/usr/bin/ksh "+scriptName+" "+argParameter;
Process proc = Runtime.getRuntime().exec(scriptToBePassed);
int exitValue = proc.waitFor();
s.o.p("Exit Value is : "+exitValue);
}
catch(Exception e)
{
  e.printStackTrace();
}

Step 2) test.ksh file internally calls an exe file and it accepts the arguments.

While running the above code , i am getting 139 exit Value.

and also note that when i am running the script manually it went successful.

Above java code will generates command:
/usr/bin/ksh test.ksh satish.

The command is used to run manually.