Windows 批处理 : run a process in background and wait for it

标签 windows batch-file windows-shell

我需要从批处理作业中启动 2 个后台进程,然后等待它们。 Unix shell 模拟是:

myprocess1 -flags1 &
pid1=$!

myprocess2 -flags2 &
pid2=$!

wait ${pid1}
wait ${pid2}

有什么想法吗?

最佳答案

您可以使用启动包装器解决它。

包装器使用 start/wait 启动进程,进程完成后它删除一个文件以发出信号。

您通过包装器启动的第一个进程,第二个您可以通过 start/wait 启动。
然后你只需要等待文件。

Echo > waiting.tmp 
Start cmd /c wrapper.bat myprocess1 -flags1
start /wait myprocess2 -flags2

:loop
if exist waiting.tmp goto :loop

wrapper.bat 的内容

start /wait %*
del waiting.tmp

关于Windows 批处理 : run a process in background and wait for it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747963/

相关文章:

C++:跟踪耗时

batch-file - 如何从bat中的完整路径中提取文件名?

java - 有什么好的方法可以通过 JDBC 原子地执行 MySQL 语句吗?

windows - 如何获取特定桌面图标的 GUID?

python - 如何通过管道传输多个 sql 和 py 脚本

c - 如何在 C 中获取堆栈跟踪?

c++ - CreateProcess 在 exe 文件无效时等待

c++ - 如何将多个菜单项添加到 windows shell 扩展?

windows - 为什么 appcmd.exe 在批处理文件中执行时表现不同?

function - 批处理脚本中的 IP 验证 - 首先通过 findstr 进行匹配,然后通过 for 循环进行验证(仅使用内置功能的窗口?