public static void execAndCheckOutput(ProcessBuilder builder,String expectedOut,String expectedErr) throws Exception {
  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()));
    assertEquals(expectedOut,outFuture.get(10,TimeUnit.SECONDS));
    assertEquals(expectedErr,errFuture.get(10,TimeUnit.SECONDS));
  }
  finally {
    executorService.shutdown();
    process.waitFor();
  }
}

public static void execAndCheckOutput ( ProcessBuilder builder , String expectedOut , String expectedErr ) throws Exception { 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 ( ) ) ) ; assertEquals ( expectedOut , outFuture . get ( 10 , TimeUnit . SECONDS ) ) ; assertEquals ( expectedErr , errFuture . get ( 10 , TimeUnit . SECONDS ) ) ; } finally { executorService . shutdown ( ) ; process . waitFor ( ) ; } }
starts the process described by ' builder ' , and asserts that it sees ' expectedout ' on stdout and ' expectederr ' on stderr . times out after 10s .
