public static void process(Process p,LineConsumer stdout,LineConsumer stderr) throws IOException {
  try (BufferedReader inputReader=new BufferedReader(new InputStreamReader(p.getInputStream()));BufferedReader errorReader=new BufferedReader(new InputStreamReader(p.getErrorStream()))){
    String line;
    while ((line=inputReader.readLine()) != null) {
      stdout.writeLine(line);
    }
    while ((line=errorReader.readLine()) != null) {
      stderr.writeLine(line);
    }
  }
 }

public static void process ( Process p , LineConsumer stdout , LineConsumer stderr ) throws IOException { try ( BufferedReader inputReader = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ; BufferedReader errorReader = new BufferedReader ( new InputStreamReader ( p . getErrorStream ( ) ) ) ) { String line ; while ( ( line = inputReader . readLine ( ) ) != null ) { stdout . writeLine ( line ) ; } while ( ( line = errorReader . readLine ( ) ) != null ) { stderr . writeLine ( line ) ; } } }
writes stdout and stderr of the process to consumers . < br > supposes that stderr of the process is redirected to stdout .
