开发者

How do I Continue a batch file only if a process IS running

I have successfully managed to hold a batch file until a process ends. But how do I hold a batch file until a process starts?

I am working using the following code:

@echo off

set process_1="calc.exe"
set process_2="mmc.exe"
set ignore_result=INFO:
set no_ignore=mmc.exe

:1
for /f "usebackq" %%M in (`tasklist /nh /fi "imagename eq %process_1%"`) do if not %%M==%ignore_result% goto 1
:2
for /f "usebackq" %%N in (`tasklist /nh /fi "imagename eq %process_2%"`) do if not %%N==%no_ignore% goto 2

echo Stuff finished.......

All I get when the program isn't runnin开发者_开发技巧g is "INFO: No tasks running with the specified criteria"

Thanks in advance

S


Redirect the err (2) to the stdout (1):

@echo off

set process_1="calc.exe" set process_2="mmc.exe" set ignore_result=INFO: set no_ignore=mmc.exe

:1 for /f "usebackq tokens=1" %%M in (tasklist /nh /fi "imagename eq %process_1%" 2^>^&1) do if not %%M==%ignore_result% goto 1 :2 for /f "usebackq tokens=1" %%N in (tasklist /nh /fi "imagename eq %process_2%" 2^>^&1) do if not %%N==%no_ignore% goto 2

echo Stuff finished.......

You could also use a sleep function (look for the one with ping command).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜