Java Runtime.getRuntime(): getting output from executing a command line program

前端 未结 12 1577
清歌不尽
清歌不尽 2020-11-22 00:18

I\'m using the runtime to run command prompt commands from my Java program. However, I\'m not aware of how I can get the output the command returns.

Here is my code:

12条回答
  •  长情又很酷
    2020-11-22 00:40

    Process p = Runtime.getRuntime().exec("ping google.com");
    
    p.getInputStream().transferTo(System.out);
    
    p.getErrorStream().transferTo(System.out);
    

提交回复
热议问题