使用cmd按顺序打开多个程序

时间:2011-10-10 09:52:30

标签: windows cmd fork

我有一系列3个程序必须一个接一个地启动。我在网上发现了类似于我想要做的事情:

start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe

我的问题是我有1000个序列要启动...... 所以我试过

start "exemple" "start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe"
start "exemple2" "start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe"

我也试过

start /b First1.exe
start /wait /b Second1.exe
start /wait /b Third1.exe

start /b First2.exe
start /wait /b Second2.exe
start /wait /b Third2.exe

这也不行...... 所以我不知道该怎么做。

任何想法? thx:)

[编辑]

让我们试着让它更清晰

start "exemple" "start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe"
start "exemple2" "start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe"

这失败了,因为第二次启动无法识别,它说windows无法找到'start / wait / b First.exe'

start /b First1.exe
start /wait /b Second1.exe
start /wait /b Third1.exe

start /b First2.exe
start /wait /b Second2.exe
start /wait /b Third2.exe

这是因为订单失败了 启动First1.exe和Second1.exe。 然后计算机等待Second1.exe的结束以启动First2.exe和Second2.exe ......

我想要的订单是 电脑启动First1.exe& First2.exe 当First1.exe完成时启动Second1.exe,当First2.exe完成时启动Second2.exe。

我想避免每次执行一个.cmd(这将是我的失败解决方案)。

我希望这次我更清楚了!

3 个答案:

答案 0 :(得分:2)

您仍在主批处理文件中等待。您希望第一/第二/第三序列对于每个循环是独立的。您希望每个周期都有自己的/等待。

start "exempel" cmd /c start /wait First.exe ^& start /wait Second.exe ^& start /wait Third.exe

将其视为向帮助团队发出指示。你希望每个帮助者“等待第一,然后等待第二,然后等待第三。”

答案 1 :(得分:2)

除主要实例外,每个序列还需要一个cmd.exe实例。操作系统没有对排序过程的内置支持,cmd.exe不支持命令文件中的线程。

你可以这样做:

 start "sequence1" cmd /c "First.exe & Second.exe & Third.exe"
 start "sequence2" cmd /c "First.exe & Second.exe & Third.exe"
 start "sequence3" cmd /c "First.exe & Second.exe & Third.exe"
 ...

避免cmd.exe额外实例(相当适度)开销的唯一方法是用真正的编程语言而不是批处理文件编写解决方案。

您可能还想考虑这是否真的是您想要做的。当数百个进程同时运行时,Windows通常不能很好地运行。

答案 2 :(得分:0)

如何在单个.CMD文件中添加调用,然后通过start执行它?

@echo off
program1.exe
program2.exe
program3.exe

为了检查一切是否正常,你可以测试.BAT / .CMD中每个单一编程的返回码(我的记忆一直告诉我%ERRORLEVEL%但是我不太确定它:()

相关问题