• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to execute shell(unix) through a servlet.

 
kajal khanna
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to execute a shell through the servlet .. but it is now working ...
i have used it in the following way ..
.
.
Process p=null;
Runtime r1=Runtime.getRuntime();
try{
p=r1.exec("sh abc");
p.waitFor();
}
catch(Exception e){}
.
.
but it is not executing the shell .. can somebody help me ...
 
MIchael Kmiec
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried referencing the shell script via a full path?
Instead of r1.exec("sh abc"), how about:
String script = "/usr/home/mike/myshellscript";
r1.exec( script );
...this may have something to do with the script residing somewhere the JVM can't find it. Try being explicit, since "exec() starts a new process running externally to the interpreter." (J.I.A.N., 3rd edition.)

------------------
 
Mohamed Yousuff
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see this question for the second time by you. I have already answered this same question in some other thread started by you.
The point is you cannot see the output of the program when you use runtime.exec() function.

Originally posted by kajal khanna:
I'm trying to execute a shell through the servlet .. but it is now working ...
i have used it in the following way ..
.
.
Process p=null;
Runtime r1=Runtime.getRuntime();
try{
p=r1.exec("sh abc");
p.waitFor();
}
catch(Exception e){}
.
.
but it is not executing the shell .. can somebody help me ...


------------------
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hope this answers your question. And don't worry about repeating a question if nobody is able to answer it correctly the first time.
Jason Menard
[This message has been edited by Jason Menard (edited June 26, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!