windows 用cmd依次打开多个程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7711072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
open multiple programs sequentially with cmd
提问by florent
i have a sequence of 3 programs that have to be launched one after another. I found on the web something like that wich is exactly what i whant to do :
我有一系列必须启动的 3 个程序。我在网上找到了类似的东西,这正是我想要做的:
start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe
My problem is that i have 1000 sequence to launch... So i tried
我的问题是我有 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"
I also tried
我也试过
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
This is not working too... So i do not know how to do it.
这也不起作用......所以我不知道该怎么做。
any idea? thx :)
任何的想法?谢谢 :)
[EDIT ]
[编辑 ]
Let's try to make it more clear
让我们试着让它更清楚
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"
This failed because the 2nd start is not recognized, it says that windows can't find 'start /wait /b First.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
This failed because the order is First1.exe and Second1.exe are launched. Then the computer wait the end of Second1.exe to launch First2.exe and Second2.exe ...
这失败了,因为顺序是 First1.exe 和 Second1.exe 被启动。然后计算机等待 Second1.exe 结束以启动 First2.exe 和 Second2.exe ...
The order i would like is The computer launch First1.exe & First2.exe Second1.exe is launched when First1.exe finished and Second2.exe is launched when First2.exe finished.
我想要的顺序是计算机启动 First1.exe & First2.exe Second1.exe 在 First1.exe 完成时启动,Second2.exe 在 First2.exe 完成时启动。
I would like to avoid using one .cmd per execution (this would be my fail solution).
我想避免每次执行使用一个 .cmd (这将是我的失败解决方案)。
I wish i'm more clear this time!
我希望这次我更清楚!
回答by Raymond Chen
You are still doing the waiting in the main batch file. You want the First/Second/Third sequence to be independent for each cycle. You want the each cycle to have its own /wait.
您仍在主批处理文件中等待。您希望每个循环的第一个/第二个/第三个序列是独立的。您希望每个循环都有自己的 /wait。
start "exempel" cmd /c start /wait First.exe ^& start /wait Second.exe ^& start /wait Third.exe
Think of it as giving instructions to a team of helpers. You want each helper to "wait for First, then wait for Second, then wait for Third."
可以将其视为向一组助手发出指示。您希望每个助手“等待第一个,然后等待第二个,然后等待第三个”。
回答by Harry Johnston
You will need one instance of cmd.exe for each sequence, in addition to the main instance. The operating system has no built-in support for sequencing processes, and cmd.exe doesn't support threading in command files.
除了主实例之外,每个序列还需要一个 cmd.exe 实例。操作系统没有对排序进程的内置支持,并且 cmd.exe 不支持命令文件中的线程。
You can do it like this:
你可以这样做:
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"
...
The only way to avoid the (fairly modest) overhead of the extra instances of cmd.exe would be to write a solution in a real programming language rather than as a batch file.
避免 cmd.exe 额外实例的(相当适度的)开销的唯一方法是用真正的编程语言而不是批处理文件编写解决方案。
You may also want to consider whether this is really want you want to do. Windows doesn't typically perform very well when hundreds of processes are running simultaneously.
您可能还需要考虑这是否真的是您想要做的。当数百个进程同时运行时,Windows 通常不会表现得很好。
回答by BigMike
what about adding invocations in a single .CMD file and then execute it via start ?
如何在单个 .CMD 文件中添加调用,然后通过 start 执行它?
@echo off
program1.exe
program2.exe
program3.exe
In order to check if everything's ok, you can test the return code of each single progs in .BAT/.CMD (my memory keeps telling me %ERRORLEVEL% but I'm not so sure about it :( )
为了检查一切是否正常,您可以测试 .BAT/.CMD 中每个单独程序的返回代码(我的记忆一直告诉我 %ERRORLEVEL% 但我不太确定:()