问题描述
我有一个Java Webstart进程,该进程是Windows批处理脚本的一部分.在这种情况下,我在批处理脚本中使用javaws命令.使用"apache commons exec"以编程方式调用此匹配脚本(start.bat).在某些情况下,javaws调用的java进程挂起,我必须从批处理脚本start.bat开始杀死整个进程线程.有没有一种编程的方法可以通过apache commons exec杀死整个进程树?
I have a Java webstart process that is part of a windows batch script. I'm using the javaws command in a batch script in this case.This match script ( start.bat) is invoked programatically using the "apache commons exec". Under some conditions the java process invoked by javaws hangs and I'd have to kill the entire process thread starting from the batch script start.bat.Is there a programatic way of doing killing an entire process tree through apache commons exec?
我尝试使用"execWatchdog.destroyProcess();"在"start.bat"脚本上.但是,它只会杀死start.bat进程,而不是整个进程树.
I've tried using the "execWatchdog.destroyProcess();" on the "start.bat" script. However it only kills the start.bat process and not the entire process tree.
是否可以通过apache-commons-exec或类似的代码杀死整个进程树?
Is there a way of killing the entire process tree through apache-commons-exec or a similar code?
我已经看到了这个问题 杀死进程树";在Windows上的c ++中在c ++中执行等效的任务.我想知道是否有人通过JNI实现了对Windows本机系统的调用.
I've seen this question Performing equivalent of "Kill Process Tree" in c++ on windows that performs an equivalent task in c++. I'm wondering if anyone has implemented calling windows native system calls through JNI.
推荐答案
即使采用环岛方式,最终还是可以解决的.
Apache Commons Exec API包含CommandLauncher类,该类返回java.lang.Process对象.感谢链接
Finally got something workable even though its a roundabout way.
Apache Commons Exec API contains the CommandLauncher class that returns a java.lang.Process object. Thanks to the link
链接从java.lang.Process获取Windows进程ID.这使用了JNA库.
Here the link to get the windows Process Id from a java.lang.Process. This uses the JNA libraries.
最后带有进程ID,这里是杀死进程树的命令字符串//String killCmd ="taskkill/F/T/PID" + JNAHandler.getPid(process);
Finally with the Process Id, here the command string that kills the process tree//String killCmd = "taskkill /F /T /PID " + JNAHandler.getPid(process);
这篇关于“杀死进程树"指的是“杀死进程树".在Windows上使用Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!