jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Execute command line command with arguments within Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Execute command line command with arguments within Web Application" Watch "Execute command line command with arguments within Web Application" New topic
Author

Execute command line command with arguments within Web Application

Guillem Plasencia
Greenhorn

Joined: Oct 13, 2010
Posts: 1
Hi,

I've been struggling through this for a while. I'm writing a Web application (run within Glassfish v3) where a Servlet will call a Class that will itself execute a command line program. The user provides an input file, which is saved in a temp folder (OK up to this point). Then,
i have to run this program passing it the absolute path to the input file, also the output of this program is another file which has to be set as a command-line argument (and other parameters). The program needs some libraries, so my app reads the needed environment variables (LD_LIBRARY_PATH in this case) from a configuration XML file, and sets it.

Here's the code:



As my log file reports, the (String-ified) program command line (with arguments) is:


the temporary folder is:


and the environment variables used is:


Unfortunately, i see no output at all in the expected temp folder, nor any Exception is raised/catched. The only clue i have about what might be wrong is the fact that Process API includes two methods: getInputStream(), getOutputStream() and getErrorStream().
The getErrorStream() gave me an error while loading shared libraries for one of the needed libraries,

-How do i set the environment variable that points to needed libraries for my command line program? (in command line it would be LD_LIBRARY_PATH, and this is just what i used but it does not recognize it properly)

-Do i have to use getInputStream() and getOutputStream() them to feed the input and read the output of the command line program? Isn't a bit misleading the fact that ProcessBuilder API includes a directory(File) to set the temporary folder, if the only way of setting program's input / reading program's output is through getInputStream and getOutputStream methods?

-I see that an OutputStream has methods to write in it, so i guess that should be my program's input, and the InputStream then would be my program's output, am i right?

Thank you very much,

Guillem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Execute command line command with arguments within Web Application
 
Similar Threads
how to pass arguments to other programs
Ubuntu and ld.so.conf vs LD_LIBRARY_PATH and java.library.path
process execution in linux
Set environment variable of UNIX by java program
Cant get the output of a class file through the following JSP