• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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 not 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 ...
 
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 hope you are using unix os. 'sh abc' is not a valid shell command. Check for other commands like 'ls'. Note that you cannot see the output of the program in the screen where you are executing. The output can be obtained as follows
BufferedReader br = new BufferedReader( new InputStreamReader(p.getInputStream()) ;
String str ;
while( (str=br.readLine() != null )
System.out.println( str ) ;

In the above code, in the constructor of InputStreamReader, p is the process object that you obtained using runtime.exec() function.
This will solve your problem

Originally posted by kajal khanna:
I'm trying to execute a shell through the servlet .. but it is not 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 ...



------------------
 
Those are the largest trousers in the world! Especially when next to this ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic