Runtime.getRuntime().exec(“C:\cygwin\bin\bash.exe”) has no input to read

前端 未结 2 1336
悲哀的现实
悲哀的现实 2021-01-14 23:08

I\'m trying to execute a new process and read from its input stream in Java. I have successfully used Runtime.getRuntime().exec(String) to start and receive input from sever

2条回答
  •  青春惊慌失措
    2021-01-14 23:37

    Regardless of Java, as far as I know you can pipe output (or input) from/to bash only when it is running as a script, not when it is running as an interactive shell (in which case you can only pass cmd parameters to it).

    In other words, when you run bash from cmd as you mention in the comment, you see output, but it is contained in the bash process, it is not output that bash sends back to the parent cmd process.

    Regarding the javac process, it is actually sending the output to the error stream. Try running from cmd javac 1>null and javac 2>null and you'll see the difference.
    Have you looked at the api here? You can try to use ProcessBuilder and redirect the error stream back to the primary input stream, it'll be much easier to work with the processes this way.

提交回复
热议问题