Process p=Runtime.getRuntime().exec(command);p.waitFor();
to execute a command, like 7zip, it somehow deadlocked and just hang there.
Chances are the zip process is blocking trying to write to standard
output. Try adding this after you run the process:
final InputStream in = p.getInputStream();
new Thread(new Runnable() {
public void run(){
try{ while (in.read() != -1);}catch (IOException e){e.printStackTrace();}
}
}).start();
p.waitFor();
Referring to javadoc on Process http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Process.html
The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(),getInputStream(),getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. 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.
沒有留言:
張貼留言