private static int grabProcessOutput(
            @NonNull final Process process,
            @NonNull final ProcessOutput output ) throws InterruptedException
    {
        Thread threadErr = new Thread( "stderr" )
        {
            @Override
            public void run()
            {
                InputStream stderr = process.getErrorStream();
                OutputStream stream = output.getErrorOutput();
                try
                {
                    ByteStreams.copy( stderr, stream );
                    stream.flush();
                }
                catch ( IOException e )
                {
                    // ignore?
                }
                finally
                {
                    try
                    {
                        Closeables.close( stderr, true /* swallowIOException */ );
                    }
                    catch ( IOException e )
                    {
                        // cannot happen
                    }
                    try
                    {
                        Closeables.close( stream, true /* swallowIOException */ );
                    }
                    catch ( IOException e )
                    {
                        // cannot happen
                    }
                }
            }
        };
        Thread threadOut = new Thread( "stdout" )
        {
            @Override
            public void run()
            {
                InputStream stdout = process.getInputStream();
                OutputStream stream = output.getStandardOutput();
                try
                {
                    ByteStreams.copy( stdout, stream );
                    stream.flush();
                }
                catch ( IOException e )
                {
                    // ignore?
                }
                finally
                {
                    try
                    {
                        Closeables.close( stdout, true /* swallowIOException */ );
                    }
                    catch ( IOException e )
                    {
                        // cannot happen
                    }
                    try
                    {
                        Closeables.close( stream, true /* swallowIOException */ );
                    }
                    catch ( IOException e )
                    {
                        // cannot happen
                    }
                }
            }
        };
        threadErr.start();
        threadOut.start();
        // it looks like on windows process#waitFor() can return
        // before the thread have filled the arrays, so we wait for both threads and the
        // process itself.
        threadErr.join();
        threadOut.join();
        // get the return code from the process
        return process.waitFor();
    }
private static int grabProcessOutput(
            @NonNull final Process process,
            @NonNull final ProcessOutput output ) throws InterruptedException
    {
        Thread threadErr = new Thread( "stderr" )
        {
            @Override
            public void run()
            {
                InputStream stderr = process.getErrorStream();
                OutputStream stream = output.getErrorOutput();
                try
                {
                    ByteStreams.copy( stderr, stream );
                    stream.flush();
                }
                catch ( IOException e )
                {
                    
                }
                finally
                {
                    try
                    {
                        Closeables.close( stderr, true  );
                    }
                    catch ( IOException e )
                    {
                        
                    }
                    try
                    {
                        Closeables.close( stream, true  );
                    }
                    catch ( IOException e )
                    {
                        
                    }
                }
            }
        };
        Thread threadOut = new Thread( "stdout" )
        {
            @Override
            public void run()
            {
                InputStream stdout = process.getInputStream();
                OutputStream stream = output.getStandardOutput();
                try
                {
                    ByteStreams.copy( stdout, stream );
                    stream.flush();
                }
                catch ( IOException e )
                {
                    
                }
                finally
                {
                    try
                    {
                        Closeables.close( stdout, true  );
                    }
                    catch ( IOException e )
                    {
                        
                    }
                    try
                    {
                        Closeables.close( stream, true  );
                    }
                    catch ( IOException e )
                    {
                        
                    }
                }
            }
        };
        threadErr.start();
        threadOut.start();
        
        
        
        threadErr.join();
        threadOut.join();
        
        return process.waitFor();
    }
private static int grabProcessOutput ( @ NonNull final Process process , @ NonNull final ProcessOutput output ) throws InterruptedException { Thread threadErr = new Thread ( "stderr" ) { @ Override public void run ( ) { InputStream stderr = process . getErrorStream ( ) ; OutputStream stream = output . getErrorOutput ( ) ; try { ByteStreams . copy ( stderr , stream ) ; stream . flush ( ) ; } catch ( IOException e ) { // ignore? } finally { try { Closeables . close ( stderr , true /* swallowIOException */ ) ; } catch ( IOException e ) { // cannot happen } try { Closeables . close ( stream , true /* swallowIOException */ ) ; } catch ( IOException e ) { // cannot happen } } } } ; Thread threadOut = new Thread ( "stdout" ) { @ Override public void run ( ) { InputStream stdout = process . getInputStream ( ) ; OutputStream stream = output . getStandardOutput ( ) ; try { ByteStreams . copy ( stdout , stream ) ; stream . flush ( ) ; } catch ( IOException e ) { // ignore? } finally { try { Closeables . close ( stdout , true /* swallowIOException */ ) ; } catch ( IOException e ) { // cannot happen } try { Closeables . close ( stream , true /* swallowIOException */ ) ; } catch ( IOException e ) { // cannot happen } } } } ; threadErr . start ( ) ; threadOut . start ( ) ; // it looks like on windows process#waitFor() can return // before the thread have filled the arrays, so we wait for both threads and the // process itself. threadErr . join ( ) ; threadOut . join ( ) ; // get the return code from the process return process . waitFor ( ) ; }
Get the stderr/stdout outputs of a process and return when the process is done.
Both <b>must</b> be read or the process will block on windows.

@param process The process to get the output from.
@param output The processOutput containing where to send the output.
Note that on Windows capturing the output is not optional. If output is null
the stdout/stderr will be captured and discarded.
@return the process return code.
@throws InterruptedException if {@link Process#waitFor()} was interrupted.
Get the stderr / stdout outputs of a process and return when the process is done . Both <b > must< / b > be read or the process will block on windows .