File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets calling unix scripts" Watch "Servlets calling unix scripts" New topic

Servlets calling unix scripts

san patil

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

Joined: Feb 09, 2004
Posts: 14
String[] cmdString = { scriptname, parm0, parm1...};
Process process = Runtime.getRuntime().exec(cmdString);
try {
} 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) {
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12982
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.
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. Mumbai, India.
Consider Paul's rocket mass heater.
subject: Servlets calling unix scripts
It's not a secret anymore!