使用Runtime.getRuntime().exec()可以调用exe
通过Runtime.getRuntime().addShutdownHook()也可以在jvm正常退出的时候结束对exe的调用。
那jvm异常退出的时候该怎么结束exe进程呢?

解决方案 »

  1.   

    异常退出 不行吧 jvm都没机会处理就被终止了
      

  2.   

    Process p = Runtime.getRuntime().exec(...);
    p.destroy();
      

  3.   

    Uncaught exceptions are handled in shutdown hooks just as in any other thread, by invoking the uncaughtException method of the thread's ThreadGroup object. The default implementation of this method prints the exception's stack trace to System.err and terminates the thread; it does not cause the virtual machine to exit or halt. 
    未捕获异常都会在shutdown hooks中处理的,楼主可能遇到的且无法处理的是什么异常呢
      

  4.   


    命令行运行时按ctrl+c,钩子有效,但是直接关闭或者在任务管理器中干掉java,钩子就没用。
    这个时候有没有方法处理呢?
      

  5.   

    你说的没错
    要是进程间能设置主从关系就ok了,就像daemon线程一样,主线程结束会连带从线程结束。
    这需要操作系统支持,不知道有没有这种功能