并行执行批处理文件并等待所有操作完成 [英] executing batch files parallel and wait till all completes

查看:557
本文介绍了并行执行批处理文件并等待所有操作完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个master batch文件,它调用了另一个列表batch文件.我想等到所有batch文件都执行完(不能说哪个文件执行得更快)并来到master batch文件来执行其余文件.

I have a master batch file which calls another list batch files. I want to wait until all the batch files are executed (cannot say which one will execute faster) and comes to master batch file to execute the remaining.

示例:

           a) master.bat            b) build.bat
              call build.bat           start web.bat        
              post.bat                 start db.bat                            

此处master.bat调用文件build.bat,并且build.bat文件并行运行web & db bat文件,一旦执行,它们必须返回到master.bat并运行post.bat.

here master.bat calls a file build.bat and build.bat files runs the web & db bat files in parallel and once they are executed, it has to return to master.bat and run the post.bat.

任何人都可以指导我如何做到这一点.

can any one please guide me how to do this.

推荐答案

最终获得解决方案,但忘了更新:)

Finally got the resolution but forgot to update :)

@echo off
setlocal
set "lock=%temp%\wait%random%.lock"

:: Launch processes asynchronously, with stream 9 redirected to a lock file.
:: The lock file will remain locked until the script ends.
start "" 9>"%lock%1" web.bat
start "" 9>"%lock%2" db.bat

:Wait for both processes to finish (wait until lock files are no longer locked)
1>nul 2>nul ping /n 2 ::1
for %%N in (1 2) do (
  (call ) 9>"%lock%%%N" || goto :Wait
) 2>nul

::delete the lock files
del "%lock%*"

:: Finish up
echo Done - ready to continue processing.

谢谢

这篇关于并行执行批处理文件并等待所有操作完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆