File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet calling remote script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet calling remote script" Watch "Servlet calling remote script" New topic

Servlet calling remote script

Kop Ite

Joined: Aug 06, 2001
Posts: 9
How do I code my servlet such that it can call a script ( Korn, Perl etc) on another Unix box (e.g. dsn123) ?
I guess that i'd need to be using Runtime.getRuntime().exec ??
.... Runtime.getRuntime().exec(" ../host/home/third/")
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
Won't that be a security violation?
Kop Ite

Joined: Aug 06, 2001
Posts: 9
Is it possible to call a script on another UNIX box from the one which the Servlet is running? I thought security violations were where you're attempting to connect with another box from an applet. I am not sure whether Servlet disallows my requirement. If so that is a shame - for me - but what if the script existed on the same machine or called a script on the same machine which then pointed at another script on another machine ???
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

Servlets are given a high level of trust, and I believe there are people in this forum who have successfully used the exec() function in servlets.
In order to run a script that lives on another machine, you obviously must have access to the interpreter, its runtimes, and the script, so you need an NFS connection just to be able to see the script, and a perl interpreter system needs to be available on the web host. Implicit execution of Perl isn't going to work - the "#!/usr/bin/perl" part is handled by the shell, and you're not using the shell. So you need to explicitly SAY exec("/usr/bin/perl ../host/home/third/");
Just as a general reminder - if you synchronously invoke a long-running process of any type, you may timeout on the user's browser and can have performance problems on the webserver. It's often best to make a server for the external process and play web games with it as an a synchronous service.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Servlet calling remote script
It's not a secret anymore!