This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlets calling unix scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets calling unix scripts" Watch "Servlets calling unix scripts" New topic
Author

Servlets calling unix scripts

san patil
Greenhorn

Joined: Mar 30, 2003
Posts: 8
Hi,
I have a unix script (san.sh). I want to call this script through a servlet.
Please suggest!
Thanks,
san
Dominik Ratajski
Greenhorn

Joined: Feb 09, 2004
Posts: 14
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
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


Java Resources at www.wbrogden.com
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
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.


Kaustubh. Mumbai, India.
 
wood burning stoves
 
subject: Servlets calling unix scripts
 
Similar Threads
umask question
how to copy a file to a different location with a part of the file name as the filename
issue in passiing variable to shell script
generate a text file in another server ??
to run a unix script