MyFile1.bat
调用了两次 MyFile2.bat
:
start MyFile2.bat argA, argB, argC
start MyFile2.bat argX, argY, argZ
现在,我该如何等待通过调用 MyFile2.bat
生成的两个进程都完成?
MyFile1.bat
调用了两次 MyFile2.bat
:
start MyFile2.bat argA, argB, argC
start MyFile2.bat argX, argY, argZ
现在,我该如何等待通过调用 MyFile2.bat
生成的两个进程都完成?
只需使用Start /WAIT参数即可。
start /wait MyFile2.bat argA, argB, argC
start /wait MyFile2.bat argX, argY, argZ
start /w cmd /c "start cmd /c MyFile2.bat argA, argB, argC & start cmd /c MyFile2.bat argA, argB, argCt"
echo X > activeProcess.argA
start MyFile2.bat argA, argB, argC
echo X > activeProcess.argX
start MyFile2.bat argX, argY, argZ
:waitForSpawned
if exist activeProcess.* goto waitForSpawned
在MyFile2.bat的结尾插入以下行:
del activeProcess.%1
ping
延迟,以便在此循环中浪费更少的CPU。%TEMP%
目录中创建标志文件。我可能会在:waitForSpawned
和条件之间添加一个小延迟,而且我会在脚本的开始处插入del
行(顺便问一下,你是不是指del activeProcess.*
?)以防万一脚本意外中断。 - Andriy Mstart MyFile2.bat argA, argB, argC
start MyFile2.bat argX, argY, argZ ^& echo.^>End.val ^& exit
:testEnd
if exist end.val (del end.val
echo Process completed
pause)
>nul PING localhost -n 2 -w 1000
goto:testEnd
start MyFile2.bat argA, argB, argC ^& echo.^>End1.val ^& exit
start MyFile2.bat argX, argY, argZ ^& echo.^>End.val ^& exit
:testEnd
if exist end.val if exist end1.val (del end.val
del end1.val
echo Process completed
pause)
>nul PING localhost -n 2 -w 1000
goto:testEnd
start
更改为call
,这是我的第一反应。然而,也许他们希望这两个调用并行运行。在这种情况下,你的建议和我的建议都不太合适。 - Andriy M