批处理 - 在关闭C结束B后启动.exe A和B.

时间:2017-02-22 18:12:24

标签: batch-file

所以我有那个启动.exe A和B的批处理,其中A是一个关闭并启动文件C的(游戏)启动器。我可以在关闭游戏后做到这一点(C)B文件关闭藏汉?

此外,我试图聚集这样的事情 -

@echo off
start A.exe
start B.exe
:CheckAgain
tasklist | findstr "TheCProgram.exe"
if errorlevel 1 (timeout /T 2 & goto :CheckAgain)
taskkill B.exe
exit

哪个不起作用......

(很抱歉,这些东西很糟糕的术语和拼写错误以及我所有的菜鸟......而且我已经失去了TT)

1 个答案:

答案 0 :(得分:1)

这是一个应该这样做的简单循环:

: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.

它检查标准窗口计算器calc.exe,这很容易启动。我在cmd中启动批处理文件,然后在超时2或3次后启动计算器。批处理文件正确检测到calc正在运行,并结束批处理文件。

相关问题