此问题出现原因在JDK document中有写明 ——

Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.

大意就是output stream空间非常有限,写满了没有释放出来,waitFor()就会无限地等下去。

简单解决方法就是用个while不停从buffer中读取数据以释放缓存,高级解决办法是利用多线程类随时读取,如StreamGobbler

解决方法源自:http://www.javaworld.com/article/2071275/core-java/when-runtime-exec—won-t.html