我有一个创建子进程的 Java Swing 应用程序。主 Swing 应用程序有一个停止按钮,点击后应立即终止子进程。“process.destroy()”不起作用。
Process myProcess = new ProcessBuilder("java", "-classpath", System.getProperty("java.class.path"), "MyClass.java");
try {
myProcess.waitFor();
}
catch (Exception e) {
e1.printStackTrace();
}
...
myStopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myProcess.destroyForcibly();
// myProcess is a really long and complex process. So I could not destroy that using process.destroyForcibly().
}
}
我可以向子进程发送一些信号以在内部调用 System.exit() 吗?
我可以使用“taskkill”来终止子进程吗?
白衣染霜花
相关分类