gpt4 book ai didi

windows - 并行执行批处理文件并等待所有完成

转载 作者:可可西里 更新时间:2023-11-01 09:24:48 27 4
gpt4 key购买 nike

我有一个 master batch 文件调用另一个列表 batch 文件。我想等到所有的batch文件都执行完了(不能说哪个执行得更快)然后来到master batch文件执行剩余。

例子:

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

这里 master.bat 调用一个文件 build.batbuild.bat 文件运行 web & db bat 文件,一旦它们被执行,它必须返回到 master.bat 并运行 post.bat

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

最佳答案

终于搞定了但是忘了更新:)

@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.

谢谢,

关于windows - 并行执行批处理文件并等待所有完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20755181/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com