等待过程中窗口的批处理文件结束 [英] wait for process to end in windows batch file
问题描述
我想编写Windows脚本等待,直到一个给定的进程(PID)执行的东西之前已经结束。到目前为止,我有(PID = 1234):
:循环
集VAR =任务列表|找到/ I1234/ C
如果没有(%VAR%')==0转到循环
**做一点事**
但已经行
组VAR =任务列表|找到/ I1234/ C
不起作用,它存储串代替评估。或者,也许它应该?在这种情况下,线
如果没有(%VAR%')==0转到循环
应该评估VAR的内容,但如果我在一个控制台手动键入此我只是得到
任务列表|找到/ I是意外
我明白双引号
组VAR =任务列表|找到/ I1234/ C
是有问题的,但我需要的PID的每侧(1234中的例子)的空间,以确保它不是另一过程的子(如12345),用于它的正常工作。
任何DOS专家那里?
:循环
任务列表|找到1234> NUL
如果没有ERRORLEVEL 1(
超时/吨,10 -10 NUL
转到:循环
)
获取列表,在搜索内容,如发现(在没有发现错误级别= 1)等待和循环
要获取数据到变量
FOR / F %%一个在('任务列表^ |找到/ C1234)并设为VAR = %%一个
I would like to write a windows script that waits until a given process (PID) has ended before executing something. So far I have (PID=1234):
:loop
set VAR="tasklist | find /i " 1234 " /c"
if NOT (' %VAR% ')=="0" goto loop
**do something**
but already the line
set VAR="tasklist | find /i " 1234 " /c"
doesn't work, it stores the string instead of the evaluation. Or maybe it's supposed to? In which case the line
if NOT (' %VAR% ')=="0" goto loop
should evaluate the contents of VAR, but if I type this manually in a console I just get
"tasklist | find /i " was unexpected
I understand the double quotes in
set VAR="tasklist | find /i " 1234 " /c"
are problematic but I need a space on each side of the PID (1234 in the example) to ensure that it is not a substring of another process (like 12345) for it to work properly.
Any DOS experts out there?
:loop
tasklist | find " 1234 " >nul
if not errorlevel 1 (
timeout /t 10 >nul
goto :loop
)
Get the list, search in the content, if found (on not found errorlevel = 1) wait and loop
To get the data into the variable
for /f %%a in ('tasklist ^| find /c " 1234 "') do set "var=%%a"
这篇关于等待过程中窗口的批处理文件结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!