等待命令完成
我有一个启动其他批处理文件的 Windows 批处理文件。在执行第一批中的某些内容之前,如何等待所有其他批处理文件完成?我无法使用 /wait 因为我需要其他命令并行运行。
I have a Windows batch file that starts other batch files. How do I wait for all the other batch files to finish before executing somthing in the first batch? I can't use /wait because I need the other commands to run in parallel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用多个标志文件,每个正在运行的批处理文件一个。例如:
第一个批处理文件在输入时创建Flagfile.1,并在结束之前将其删除,并且以同样的方式其余并发批处理文件(Flagfile.2,...)
主文件必须等待所有flagfile消失。例如,在主文件中:
在任何批处理文件中,例如 Batch1:
You may use several flag files, one per running Batch file. For example:
First batch file create Flagfile.1 when enter, and delete it before end, and the same way the rest of concurrent batch files (Flagfile.2,...)
The main file just must wait for all flagfiles disappear. For example, in Main file:
In any Batch file, for example Batch1:
我的建议是使用
CALL
命令。 批处理文件中的示例:Batch1.bat 列表:
其中 Batch2.bat 列表为:
EDIT: based on feedback from @Andriy M, here is an improved version for the two batches:
第 1 批:
第 2 批:
请参阅第 1 批中的行,其中我写了注释使用 CALL 测试此行,不使用 CALL。运行该批处理两次,该行有
CALL
和没有CALL
。控制台的输出不带
CALL
:现在控制台的输出带
CALL
:请注意区别:我们得到第二个回声,qed
My suggestion is to use
CALL
command. An example from Batch Files:Batch1.bat listing:
where Batch2.bat listing is:
EDIT: based on feedback from @Andriy M, here is an improved version for the two batches:
Batch 1:
Batch 2:
See the line in batch1 where I wrote the comment test this line with CALL and without. Run that batch twice, with that line having
CALL
and withoutCALL
.The output from console without
CALL
:And now the output from console with
CALL
:Please note the difference: we get the 2nd echo, q.e.d.