Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 20131 invoked from network); 2 Mar 2002 01:07:21 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 2 Mar 2002 01:07:21 -0000 Received: (qmail 18973 invoked by uid 97); 2 Mar 2002 01:07:24 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 18944 invoked by uid 97); 2 Mar 2002 01:07:23 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 18933 invoked by uid 97); 2 Mar 2002 01:07:23 -0000 Date: 2 Mar 2002 01:07:14 -0000 Message-ID: <20020302010714.80254.qmail@icarus.apache.org> From: donaldp@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl DefaultExecManager.java Environment.java ProcessMonitor.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N donaldp 02/03/01 17:07:14 Modified: proposal/myrmidon/src/java/org/apache/aut/nativelib/impl DefaultExecManager.java Environment.java ProcessMonitor.java Log: Rework it so that ExecManager does not shutdown streams. Important when you pass in System.out/System.err or want to do something special to stream after processing. Submitted By: Darrell DeBoer Revision Changes Path 1.9 +2 -2 jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/DefaultExecManager.java Index: DefaultExecManager.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/DefaultExecManager.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DefaultExecManager.java 21 Feb 2002 09:27:21 -0000 1.8 +++ DefaultExecManager.java 2 Mar 2002 01:07:13 -0000 1.9 @@ -32,7 +32,7 @@ * * @author Peter Donald * @author Thomas Haas - * @version $Revision: 1.8 $ $Date: 2002/02/21 09:27:21 $ + * @version $Revision: 1.9 $ $Date: 2002/03/02 01:07:13 $ * @see ExecManager * @see ExecMetaData * @see Environment @@ -115,7 +115,7 @@ final CommandLauncher launcher = getLauncher( command ); final Process process = launcher.exec( command ); final ProcessMonitor monitor = - new ProcessMonitor( process, input, output, error, timeout ); + new ProcessMonitor( process, input, output, error, timeout, false ); final Thread thread = new Thread( monitor, "ProcessMonitor" ); thread.start(); 1.4 +12 -7 jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/Environment.java Index: Environment.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/Environment.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Environment.java 21 Feb 2002 09:27:21 -0000 1.3 +++ Environment.java 2 Mar 2002 01:07:13 -0000 1.4 @@ -19,6 +19,7 @@ import org.apache.aut.nativelib.ExecMetaData; import org.apache.aut.nativelib.Os; import org.apache.avalon.excalibur.util.StringUtil; +import org.apache.avalon.excalibur.io.IOUtil; /** * This is the class that can be used to retrieve the environment @@ -26,7 +27,7 @@ * * @author Peter Donald * @author Thomas Haas - * @version $Revision: 1.3 $ $Date: 2002/02/21 09:27:21 $ + * @version $Revision: 1.4 $ $Date: 2002/03/02 01:07:13 $ */ final class Environment { @@ -157,13 +158,17 @@ final ExecMetaData metaData = new ExecMetaData( command, null, workingDirectory ); final ByteArrayOutputStream output = new ByteArrayOutputStream(); - final int retval = m_execManager.execute( metaData, null, output, output, 0 ); - if( retval != 0 ) - { - // Just try to use what we got - } + try { + final int retval = m_execManager.execute( metaData, null, output, output, 0 ); + if( retval != 0 ) + { + // Just try to use what we got + } - return output.toString(); + return output.toString(); + } finally { + IOUtil.shutdownStream( output ); + } } /** 1.6 +39 -5 jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/ProcessMonitor.java Index: ProcessMonitor.java =================================================================== RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/aut/nativelib/impl/ProcessMonitor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ProcessMonitor.java 6 Feb 2002 13:34:46 -0000 1.5 +++ ProcessMonitor.java 2 Mar 2002 01:07:13 -0000 1.6 @@ -21,7 +21,7 @@ * It will also in the future do the same for stdin. * * @author Peter Donald - * @version $Revision: 1.5 $ $Date: 2002/02/06 13:34:46 $ + * @version $Revision: 1.6 $ $Date: 2002/03/02 01:07:13 $ */ class ProcessMonitor extends AbstractLogEnabled @@ -72,11 +72,33 @@ */ private final OutputStream m_error; + /** + * Specifies whether the monitor should shutdown + * input, output and error Streams when it finishes execution. + * This should be set to true for processes which + * will run asynchronously. + */ + private final boolean m_shutdownStreams; + + /** + * Creates a monitor for a given {@link java.lang.Process}, which pipes + * input from the given input stream to the process, and pipes the process + * output to the given OutputStreams. + * + * @param process the Process to be monitored + * @param input is read into the Process' stdin + * @param output receives the Process' stdout + * @param error receives the Process' stderr + * @param timeoutDuration how long to let the Process run before killing it. + * @param shutdownStreams specifies if the monitor should shutdown the + * streams when the Process exits. + */ public ProcessMonitor( final Process process, final InputStream input, final OutputStream output, final OutputStream error, - final long timeoutDuration ) + final long timeoutDuration, + final boolean shutdownStreams ) { if( null == process ) { @@ -100,6 +122,7 @@ m_output = output; m_error = error; m_timeout = timeout; + m_shutdownStreams = shutdownStreams; } /** @@ -139,9 +162,20 @@ //that we have got all the data processStreams(); - IOUtil.shutdownStream( m_input ); - IOUtil.shutdownStream( m_output ); - IOUtil.shutdownStream( m_error ); + cleanupStreams(); + } + + /** + * Utility method which cleans up all IO Streams, if required. + */ + private void cleanupStreams() + { + if( m_shutdownStreams ) + { + IOUtil.shutdownStream( m_input ); + IOUtil.shutdownStream( m_output ); + IOUtil.shutdownStream( m_error ); + } } /** -- To unsubscribe, e-mail: For additional commands, e-mail: