ProcessBuilder redirected to standard output

前端 未结 2 1073
Happy的楠姐
Happy的楠姐 2021-02-18 14:56

I would like to redirect a java process output towards the standard output of the parent java process.

Using the ProcessBuilder class as follows:

public          


        
2条回答
  •  时光说笑
    2021-02-18 15:28

    You did miss a key piece, you actually need to start your process and wait for your output. I believe this will work,

    processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    // Start the process.
    try {
      Process p = processBuilder.start();
      // wait for termination.
      p.waitFor();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    

提交回复
热议问题