Redirect stdin and stdout in Java

后端 未结 2 726
小鲜肉
小鲜肉 2020-12-03 09:05

I\'m trying to redirect stdin and stdout of a subprocess in java, eventually i\'m going to have the output go to a JTextArea or something.

Here is my current code,

2条回答
  •  半阙折子戏
    2020-12-03 09:40

    Nowadays Runtime.getRuntime().exec() is deprecated (for all practical purposes). Better use the ProcessBuilder class; in particular, its start() method will return a Process object with methods for accessing the stdin and stdout streams, which can be redirected wherever you need them. Take a look at this post for further details.

提交回复
热议问题