在TASKKILL之后运行的进程

时间:2016-03-23 18:21:15

标签: windows batch-file

问题与下面显示的脚本有关:

@echo on
:MAIN
start "myname" cmd /c "build\jre\bin\java -jar MainThread.jar"
timeout /t 2 >null
TASKLIST /v /fi "IMAGENAME eq cmd.exe">myfile.txt
TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
TASKLIST /v /fi "IMAGENAME eq cmd.exe">myfile2.txt
:exit

当我第一次执行tasklist时,myname被列在TASKLIST中。执行taskkill后,myname进程没有显示在TASKLILL之后执行的TASKLIST中但它正在运行。虽然它的名字在TASKLIST中不存在,但是它正在执行.TASKKILL成功地删除了它的进入但没有杀死这个过程。我该如何杀死这个过程?

2 个答案:

答案 0 :(得分:0)

已启动java进程会占用父级cmd窗口名称,但不会超过后一个父级cmd进程终止。使用未安装where的替换java给出的证明(作为where.exe运行一段时间以截取屏幕截图甚至检查任务管理器)。

测试脚本

@echo on
:MAIN
start "myname" cmd /C where /R c:\ "whistle.*" 
@timeout /t 1 >null
TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
TASKLIST /v /NH /fi "IMAGENAME eq Where.exe" /FO "CSV"
TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
:exit

<强>输出

==> D:\bat\SO\36185868.bat

==> start "myname" cmd /C where /R c:\ "whistle.*"

==> TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
"cmd.exe","3340","Console","1","2 240 K","Running","pcn\usern","0:00:00","myname"

==> TASKLIST /v /NH /fi "IMAGENAME eq Where.exe" /FO "CSV"
"where.exe","5188","Console","1","3 184 K","Unknown","pcn\usern","0:00:01","N/A"

==> TASKKILL /f /fi "IMAGENAME eq cmd.exe" /fi "WINDOWTITLE eq myname"
SUCCESS: The process with PID 3340 has been terminated.

==> TASKLIST /V /NH /fi "WINDOWTITLE eq myname" /FO "CSV"
"where.exe","5188","Console","1","3 184 K","Running","pcn\usern","0:00:01","myname"

==>

<强>截图

tasks

答案 1 :(得分:0)

谢谢你们的帮助。 我使用了TASKKILL / f / t / fi“IMAGENAME eq cmd.exe”/ fi“WINDOWTITLE eq myname”命令。 / t用于关闭所有子进程,其子进程中的1个java.exe已关闭。