• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic