Run batch files sequentially

后端 未结 3 524
清歌不尽
清歌不尽 2020-12-10 13:24

I want to ask you all how to run batch files sequentially in Windows. I have tried :

start /w batchfile_1.bat 
start /w batchfile_2.bat
..
start /w batchfile         


        
3条回答
  •  有刺的猬
    2020-12-10 14:02

    I'm not sure but based on your comments, the following seems to be happening when you run that sequence of START commands:

    1. A START /W command is invoked and starts a batch file.

    2. The batch file starts executing and runs a program.

    3. The batch file finishes and its console window remains open, but the program continues running.

    4. The START /W command that was used to run the batch file is still executing because the console window remains open.

    5. You wait until the program terminates, then you close the console window, and then the next START /W command is invoked, and everything is repeated.

    Now, if you place EXIT at the end of every batch file you want to run sequentially, that makes situation worse because it causes the console window to close after the batch script completes, and that in turn ends the corresponding START /W command and causes another one to execute, even though the program invoked by the batch script may still be running. And so the effect is that the batch scripts (or, rather, the programs executed by them) run simultaneously rather than sequentially.

    I think, if this can be solved at all, you need to move the START /W command and put it in every batch file in front of (every) command that that batch file executes and doesn't wait for the termination of. That is, if your batchfile_1.bat runs a program.exe, change the command line to START /W program.exe, and similarly for other relevant commands in other batch files.

提交回复
热议问题