java进程停止整个进程树
我正在使用 Java 运行时运行命令,包括某些 CVS 命令。
我使用:
process = runtime.exec ("cmd /C cvs...");
格式在Java中运行进程
我需要有停止它的选择。为此,我使用 Java Process destroy 方法
process.destroy();
但是,只有 cmd 停止,cvs 进程没有停止。它继续作为单独的进程运行,而没有 cmd 进程作为父进程。
网上有很多这方面的参考,但我还没有找到令人满意的解决方案。谢谢
I am using Java Runtime to run commands, including certain CVS commands.
I use:
process = runtime.exec ("cmd /C cvs...");
format for running the Process in Java
I need to have the option of stopping it. For this I use the Java Process destroy method
process.destroy();
However only the cmd is stopped not the cvs process. It continues to run as a separate process without the cmd process as the parent.
There are many references to this on the internet, but I haven't found any satisfactory solution. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Windows
cmd
shell 的问题。你为什么使用它?你不能用exec("cvs ...")
来代替吗?This is a problem with the windows
cmd
shell. Why do you use it? Can't you doexec("cvs ...")
instead?可以使用 Runtime.exec 来获取已运行进程的 PID。这样您就可以关闭进程树。
然而,您需要另外 2 个程序来查找 PID 并终止进程树。
It may be possible using Runtime.exec to get the PID of the process you have run. And with that you might be able to shut down the process tree.
You would however need 2 other programs to find the PID and to terminate the process tree.