private static int await( Process process ) { return new ProcessStreamHandler( process, true ).waitForResult(); }
args.addAll( asList( arguments ) ); Process process = Runtime.getRuntime().exec( args.toArray( new String[args.size()] ) ); final ProcessStreamHandler processOutput = new ProcessStreamHandler( process, false ); processOutput.launch(); final Future<Integer> realFuture = FutureAdapter.processFuture( process ); return new Future<Integer>()
@Override public Integer get() throws InterruptedException, ExecutionException { try { return realFuture.get(); } finally { processOutput.done(); } }
@Override public boolean cancel( boolean mayInterruptIfRunning ) { try { return realFuture.cancel( mayInterruptIfRunning ); } finally { processOutput.done(); } }
private void execAndWait( String... args ) throws Exception { Process process = Runtime.getRuntime().exec( args ); new ProcessStreamHandler( process, true ).waitForResult(); }
@Override public Integer get( long timeout, TimeUnit unit ) throws InterruptedException, ExecutionException, TimeoutException { try { return realFuture.get( timeout, unit ); } finally { processOutput.done(); } } };