Reputation:
I run process from my Java code like this p = run.exec("cmd /c start \"\" C:\\<nameof .cmd file>");
. At some point, I want to kill this process. Calling destroy()
method on process kill the process, but I want to turn off command line, where procces is still running. When I looked to Task Manager, this process has no name, it has only postfix .exe
.
In Task Manager, it look like this:
So I cannot do this p = run.exec("taskkill /F /IM <nameofexe>.exe");
, because this running process dont have name.
Is there a way, how to completely turn off cmd and kill this running process?
Upvotes: 1
Views: 3708
Reputation: 70909
When you launched your process, the CMD call may have launched additional child processes. Odds are good your second command line is killing one of the children, but not the CMD itself. The ideal situation would be to kill the launched process, not to run a second command line executable to kill (possibly) one of the children.
Process child = run.exec("cmd /c start \"\" C:\\<nameof .cmd file>");
if (timeToKillTheProcess) {
child.destroy();
child.waitFor();
}
Upvotes: 0