Java hangs when trying to close a ProcessBuilder OutputStream

后端 未结 3 1659
旧巷少年郎
旧巷少年郎 2020-12-21 16:58

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

3条回答
  •  旧时难觅i
    2020-12-21 17:20

    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 ).

提交回复
热议问题