V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
XhstormR
V2EX  ›  问与答

运行在 CMD 中的 Java 程序, Ctrl+C 强制终止后,如何对该 Java 程序另外启动的程序也进行强制终止?

  •  
  •   XhstormR · 2016-10-25 11:30:35 +08:00 · 1015 次点击
    这是一个创建于 2755 天前的主题,其中的信息可能已经有所发展或是发生改变。

    https://github.com/XhstormR/GetBilibili

    上面的是我写的一个程序,会在后台调用 FFmpeg。

    有时我强制终止了 Java 程序,但发现后台的 FFmpeg 还在进行合并。

    下面的是我写的一个示例代码:

    public class A {
        public static void main(String[] args) throws IOException {
            Process process = new ProcessBuilder().command("notepad.exe").start();
            while (true) {
                System.out.println("123");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    

    想实现在 Ctrl+C 后,记事本也能自动退出,有办法实现吗?谢谢各位了。

    2 条回复    2016-10-25 23:13:29 +08:00
    XhstormR
        1
    XhstormR  
    OP
       2016-10-25 16:32:33 +08:00
    已解决。
    snsd
        2
    snsd  
       2016-10-25 23:13:29 +08:00
    @XhstormR 能说说解决方案吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4994 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.