File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet calling remote script" Watch "Servlet calling remote script" New topic
Author

Servlet calling remote script

Kop Ite
Greenhorn

Joined: Aug 06, 2001
Posts: 9
Hi,
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/script.pl")
cheers
Adrian Yan
Ranch Hand

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

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: 15960
    
  19

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/script.pl");
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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
wood burning stoves
 
subject: Servlet calling remote script
 
Similar Threads
can I invoke java commands from a class?
How do you call a .bat file from a Java program
servlet calling perl script - script hangs
how to call .exe file by clicking the JButton..?
Executing an exe from a java program