wood burning stoves 2.0*
The moose likes Servlets and the fly likes Problem  running unix script through servlet 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 » Servlets
Bookmark "Problem  running unix script through servlet" Watch "Problem  running unix script through servlet" New topic
Author

Problem running unix script through servlet

san patil
Greenhorn

Joined: Mar 30, 2003
Posts: 8
Hi,
I have written the below code to run the unix shell script.
----------------------------------------------------------
public String runProcess(String aProcessName)
{
String vStatus="";
try
{
aProcessName = "/opt/jrun/restart/restart.sh";
Process process = Runtime.getRuntime().exec(aProcessName);
try
{
process.waitFor();
}
catch(InterruptedException ie)
{
vStatus = "Error : interrupted while waiting for app to end"+ie;
}

int vExitStatus = process.exitValue();
if (vExitStatus == 0)
{
// success
vStatus = "Success";
}
else
{
//Failed- It is faling with vExitStatus =1;
vStatus = "Error : Failed to execute the script." +vExitStatus;
}
} catch (Exception e)
{
vStatus = "Error : Unable to execute the script."+e;
}
return vStatus;
}
----------------------------------------------------------
Any suggestions!
Thanks,
San
Steve Leach
Ranch Hand

Joined: Sep 24, 2003
Posts: 46
Any suggestions about what ?
san patil
Greenhorn

Joined: Mar 30, 2003
Posts: 8
Suggestions why it is failing when code seems to be alright.
Anuradha Krishna
Greenhorn

Joined: Mar 14, 2004
Posts: 6
Hi,
Does the Unix script specify the shell interpreter (ksh/sh) to be used ? If not, it is likely that the servlet is unable to understand which interpreter to use to execute the Unix script.
HTH.
Regards,
Anuradha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem running unix script through servlet