There are many reasons why waitFor() does not return.
But usually it comes down to the fact that the executed command does not leave.
This, again, can have many reasons.
One common reason is that the process produces some output and you are not reading from the corresponding threads. This means that the process is blocked as soon as the buffer is full, and waits for your process to continue reading. Your process, in turn, is waiting for the completion of another process (which will not be because it is waiting for your process, ...). This is a classic deadlock situation.
You need to constantly read from the input process stream to ensure that it is not blocked.
There's a good article that explains all the pitfalls of Runtime.exec() and shows the paths around them called "When Runtime.exec () will not be" (yes, the article is from 2000, but the content is still applied!)
Joachim Sauer Mar 30 '11 at 8:31 2011-03-30 08:31
source share