commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Baumgartner <>
Subject Re: [exec] Draining process output/error
Date Wed, 03 Aug 2011 20:25:43 GMT
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?
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message