Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem running unix script through servlet

 
san patil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions about what ?
 
san patil
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suggestions why it is failing when code seems to be alright.
 
Anuradha Krishna
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic