我刚刚通过exec()调用创建了一个进程,现在我正在使用它的.waitFor()方法.我需要捕获一个InterruptedException,但我不确定我应该在catch代码块中放置什么.我想收到退出代码,但如果当前线程被中断,我不会.如果线程被中断,我该怎么办才能让退出代码退出进程?
例:
import java.io.IOException;
public class Exectest {
public static void main(String args[]){
int exitval;
try {
Process p = Runtime.getRuntime().exec("ls -la ~/");
exitval = p.waitFor();
System.out.println(exitval);
} catch (IOException e) {
//Call failed, notify user.
} catch (InterruptedException e) {
//waitFor() didn't complete. I still want to get the exit val.
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个启动JVM(2)的JVM(1).我希望能够在JVM(1)中监视来自JVM(2)的System.out.println()调用.