下面是一个简单的循环应该这样做:
:CheckAgain
tasklist | findstr "TheCProgram.exe"
if errorlevel 1 (timeout /T 2 & goto :CheckAgain)
分拆下来:
:CheckAgain :: A label for the start of the loop
tasklist :: Get list of running programs
findstr "TheCProgram.exe" :: Search to see if the program C is running?
if errorlevel 1 :: If there was an error, then the program is not yet running.
timeout /T 2 :: Wait 2 seconds
& goto :CheckAgain :: Go start the loop again to look for the program.
(轻测试,可能不稳固的)
这里是我所使用的示例脚本,
@echo off
:CheckAgain
tasklist | findstr "calc.exe"
if errorlevel 1 (timeout /T 2 & goto :CheckAgain)
echo The Calculator Program is now running.
它检查对于易于启动的标准Windows计算器calc.exe
。我在cmd
开始批处理文件,然后在超过2或3次后启动计算器。批处理文件正确检测到calc
正在运行,并结束批处理文件。
'/ wait'本身不是一个命令。这是“START”命令的一个选项。 – Squashman
'睡眠'也不是一个标准命令,建议您在**命令提示符**窗口中输入以下内容以了解更多信息。 'Start /?','Timeout /?','TaskKill /?'。一旦您了解了这些命令的工作方式,请更新上面的脚本,根据需要编辑该帖子。 – Compo
谢谢!我想我现在有点了解我不能使用启动命令,对吧?然后如何让脚本等待exe(不是由批处理启动)? – araraf