如果僅僅是用process.waitFor()的話,如果進程掛起這個將永遠得不到返回值,是用捕捉getExitValue異常的辦法可以work around
private int myWaitProcessFinish(Process process) throws InterruptedException{
boolean finish = false;
int exitValue = -1;
int timeout = 0;
while(!finish && 60 < timeout++){
try{
exitValue = process.exitValue();
finish = true;
} catch(Exception e) {
Thread.sleep(500);
}
}
return exitValue;
}