• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Execute command line command with arguments within Web Application

 
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 am going to test your electrical conductivity with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic