commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siegfried Goeschl <>
Subject Re: [exec] Draining process output/error
Date Thu, 04 Aug 2011 17:57:50 GMT
Hi Diane,

I think the best is to have a look at the JUnit test of commons-exec - 
there are a few examples how to consume stdout/stderr either pumping 
into stdout/stderr or collecting into a byte[]

Regarding your requirements

+) is it possible that your code can get stuck - if yes checkout Watchdog
+) please note that there are issues killing grand-children processes of 
your child process (think recursive killing)


Siegfried Goeschl

On 03.08.11 22:25, Diane Baumgartner wrote:
> Hi all,
> I'm trying to run a shell script from a Java program.  I finally got a trivial example
working wtih ProcessBuilder, and learned that I had to be sure to capture the child process's
output so that my program would work correctly.  I have also seen the warning in the Sun documentation
which states, "It is possible that the examples will deadlock if the subprocess generates
enough output to overflow the system.  A more robust solution requires draining the process
stdout and stder in separate threads."  That got me looking for information on draining these
streams, and also led me to find Apache commons exec. 
> My ultimate goal is to have the following.
> a. Java program calls shell script when user pushes a button.
> b. Shell script executes a sql script.  This script produces several output files, some
of which can be large.
> c. Shell script then calls a java program which uses Apache Commons Net to FTP the files
to an FTP server.
> I have already successfully tested parts b and c, so now I'm trying to add part a (Java
calls shell script).  My problem is that I'm having a hard time finding examples of how to
drain the stdout/stderr for large amounts of data.  I have looked at the documentation, but
don't have much experience with dealing with either streams or threads.  Can you please point
me in the right direction?
> Thanks.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message