My Java program uses ProcessBuilder (with redirectErrorStream set true) and has a loop that runs the processes’s inputstream’s read method, which is blocking. The external program I’m calling then comes to a stop waiting for input and stdin. I now want to kill the process. Is this not done by (in a seperate thread) calling the process’s destroy method, and calling the inputstream’s close method to stop the read method from blocking anymore, so that my initial thread can end its life?
For some reason process.getInputStream().close() blocks. From the JavaDoc I don’t see why this can happen. Furthermore, I don’t understand why the javadoc says ‘The close method of InputStream does nothing.’ (link to javadoc) Could someone explain this?
Thanks 🙂
Regarding the blocking behavior, there is a known issue in Java that can cause deadlock when communicating with another process. I can’t tell if this is what you’re seeing but it’s worth looking into. The document for java.lang.Process says: