calling batch files with ‘exit’

Consider ‘main.bat


call child1.bat
call child2.bat

What happens after ‘child1.bat‘ is finished?

I reasonably expected that ‘child2.bat‘ is executed. In a ideal world, yes.

In the real world, the first script contains the command ‘exit‘, and this commands not only exists from ‘child1.bat‘, but also terminates ‘main.bat‘. Therefore, ‘child2.bat‘ isn’t executed. I don’t have words to comment this behavior.

As a workaround, I constructed the following. Not sure it’s correct, but right now it works for me.


start /B /wait child1.bat
start /B /wait child2.bat

And the order of the arguments is important. “/B wait” makes the trick, “/wait /B” doesn’t.

From documentation:

* /B: Start application without creating a new window. The application has ^C handling ignored. Unless the application enables ^C processing, ^Break is the only way to interrupt the application
* /WAIT: Start application and wait for it to terminate

Leave a Reply