相关疑难解决方法(0)

在ThreadInterrupted的情况下提取进程的退出代码

我刚刚通过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)

java multithreading process interrupted-exception

4
推荐指数
1
解决办法
9117
查看次数

捕获来自另一个进程的system.out消息

我有一个启动JVM(2)的JVM(1).我希望能够在JVM(1)中监视来自JVM(2)的System.out.println()调用.

java

3
推荐指数
1
解决办法
63
查看次数