开发者

open multiple programs sequentially with cmd

开发者 https://www.devze.com 2023-04-12 02:51 出处:网络
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 :

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 :

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

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 /开发者_Go百科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'

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

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.

I would like to avoid using one .cmd per execution (this would be my fail solution).

I wish i'm more clear this time!


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.

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.

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.


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.

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


what about adding invocations in a single .CMD file and then execute it via 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 :( )

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号