I have the following Java code to start a ProcessBuilder, open an OutputStream, have the process write a string to an OutputStream, and then close the OutputStream. The who
You need to make sure that the streams returned by getInputStream()
and getOutputStream()
are drained on individual threads and these threads are different from the one on which you close the stream returned by getOutputStream()
.
Basically it is a requirement to have at least 3 threads per sub-process if you want to manipulate and examine its stdin, stdout and stderr. One of the threads, depending on your circumstances, may be your current execution thread ( the one on which you create ProcessBuilder ).