question: public static String execAndGetOutput ( ProcessBuilder builder ) throws IOException { Process process = builder . start ( ) ; ExecutorService executorService = Executors . newFixedThreadPool ( 2 ) ; try { Future < String > errFuture = executorService . submit ( streamToStringCallable ( process . getErrorStream ( ) ) ) ; Future < String > outFuture = executorService . submit ( streamToStringCallable ( process . getInputStream ( ) ) ) ; Throwable failure ; String out = "" ; try { out = outFuture . get ( 30 , TimeUnit . SECONDS ) ; String err = errFuture . get ( 30 , TimeUnit . SECONDS ) ; failure = err . length ( ) > 0 ? new AssertionFailedError ( "Unexpected err stream data:\n" + err ) : null ; } catch ( Exception e ) { failure = e ; } if ( failure != null ) { AssertionFailedError error = new AssertionFailedError ( "Failed to execute " + builder . command ( ) + "; output was:\n" + out ) ; error . initCause ( failure ) ; throw error ; } else { return out ; } } finally { executorService . shutdown ( ) ; } }
target:  Starts the specified process, collects its output from standard out and standard err, and returns. If the stream emits anything to standard err, an AssertionFailedError will be thrown. <p>This method assumes the target process will complete within thirty seconds. If it does not, an AssertionFailedError will be thrown.