Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute command line command with arguments within Web Application  RSS feed

Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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,

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!