如何在退出之前等待所有批处理文件完成?
我有一个主批处理文件,而不是调用其他4个批处理文件,所以我们可以并行运行。
例:
Main.bat
start call batch1.bat
start call batch2.bat
start call batch3.bat
start call batch4.bat
exit
我希望Main.bat在所有batch1到batch 4停止执行后退出。通过这种方式,我可以获得批处理文件的总运行时间。问题是Main.bat甚至在batch1到batch4完成执行之前退出。
我尝试为每个批处理文件计算%errorlevel%,但即使4 .bat文件仍在运行,它总是返回0。
希望有人可以帮助我!
查看完整描述
start call batch2.bat
start call batch3.bat
start call batch4.bat) | set /P "="echo %time%
在此方法中,主文件中的等待状态是
事件驱动的
,因此它不消耗任何CPU时间!
编辑
:
添加了一些解释
该
set /P
命令将终止命令当有人在
( block )
一个线路输出,但
start
命令不显示任何线
在此的cmd.exe
。这样,
set /P
在
start
命令启动的所有进程结束之前,一直等待输入。此时,与之关联的管道
( block )
关闭,因此
set /P
Stdin关闭,
set /P
操作系统终止命令。
查看完整回答
TA贡献1695条经验 获得超3个赞
试一试。
@echo offecho %time%start "" /wait cmd /c bat1.bat |start "" /wait cmd /c bat2.bat |start "" /wait cmd /c bat3.batecho %time%pause
查看完整回答