Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

how to execute shell(unix) through a servlet.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)

------------------
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...



------------------
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic