How to wait all batch files to finish before exiting?

I think this is the simplest and most efficient way:

@echo off

echo %time%

(
    start call batch1.bat
    start call batch2.bat
    start call batch3.bat
    start call batch4.bat
) | set /P "="

echo %time%

In this method the waiting state in the main file is event driven, so it does not consume any CPU time!

EDIT: Some explanations added

The set /P command would terminate when anyone of the commands in the ( block ) outputs a line, but start commands don’t show any line in this cmd.exe. This way, set /P keeps waiting for input until all processes started by start commands ends. At that point the pipe line associated to the ( block ) is closed, so the set /P Stdin is closed and set /P command is terminated by the OS.

Leave a Comment