Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I'm trying to enable command-line processing within a Java application to automate certain events whenever command-line arguments as passed into the application.

There are two applications which are executing, management and reports. The idea is to allow the management software to launch the reports software with command-line arguments, which will then automatically generate a report and store the result on the file-system. Seems simple enough.

I've managed to piece together code to accomplish this (the command-line arguments which are passed into the reports Java application are not always the same, thus this cannot be accomplish via script.) It looks something like this:

Java
ProcessBuilder processBuilder = new ProcessBuilder(
 "/path/to/javaw",
 "-Djava-library.path=.",
 "-jar",
 "/path/to/jar/file"
);
processBuilder.directory("/path/to/jar/directory");
processBuilder.command().add("/auto");
processBuilder.command().add("someParameter");
processBuilder.start();


This works fine, launching the reports Java application and running through the command-line processing algorithm.

What I'm finding, however, is that the reports Java application is suspended until the launching management Java application is shutdown. Only then does the reports Java application continue processing as it should.

I believe it has something to do with loading library dependencies. After putting in an enormous collection of debug statements, I've come to realise that the reports application suspends when it comes to loading a Jasper Reports library. The application freezes, and when management is shutdown the library is loaded and continues.

Can anyone think of a reason why this might behave this way? I can confirm that launching the reports JAR file directly using javaw works fine, and reports are created. It's just when launching through this methodology that the application hangs until the management javaw process has exited.

Thanks in advance!
Posted

1 solution

You need to drain the output streams to prevent hanging. Check the links for some detailed info.

http://www.rgagnon.com/javadetails/java-0014.html[^]
http://steveliles.github.io/invoking_processes_from_java.html[^]

Good luck!
 
Share this answer
 
Comments
Chris Copeland 1-Dec-15 11:24am    
That fixed the issue up, thanks for the help!
E.F. Nijboer 1-Dec-15 12:14pm    
Happy to help :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900