检查应用程序是否仍在批处理文件中运行?

1 windows batch-file taskmanager

如何使用批处理文件检查应用程序是否仍在运行?如果应用程序仍在运行,则此过程将一次又一次地循环.否则,将会出现错误消息.

非常感谢你

小智 5

在Windows中,您可以使用pstools pslist通过使用.cmd脚本来检查进程名称是否正在运行,如下所示.如果进程正在运行,Pslist将返回ERRORLEVEL 0,否则返回1.

@echo off

CommandYouWillRun.exe

rem waiting for the process to start
:startcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 goto startcmd

rem the process has now started

:waitforcmd
sleep 1
c:\path\to\pslist.exe CommandYouWillRun > NUL
IF ERRORLEVEL 1 got finished
goto waitforcmd

:finished
echo "This is an error message"
Run Code Online (Sandbox Code Playgroud)