• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets calling unix scripts

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a unix script (san.sh). I want to call this script through a servlet.
Please suggest!
Thanks,
san
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try:
String[] cmdString = { scriptname, parm0, parm1...};
Process process = Runtime.getRuntime().exec(cmdString);
try {
process.waitFor()...
} catch (InterruptedException)
if you're returning a value from the script the process.waitFor() can be used as a condition statement ie:
if (process.waitFor() == 0) {
DSR
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if the script does output to standard out or err, you better consume the streams - see java.lang.Process - getErrorStream() etc.
If you don't consume the streams you get very odd results.
Bill
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you might be able to use the Runtime. But make sure u have all the permissions. I was once trying touse runtime to execute a simple "dir" command on windows. But it returned me an Exception that I do not hv enough permissions to do so.
Dont know why..
-Kaustubh.
 
reply
    Bookmark Topic Watch Topic
  • New Topic