To control the flow of a batch file, there is goto :-( if errorlevel 2 goto label2Īs others pointed out: have a look at build systems to replace batch files.Īs you have noticed executing the bat directly without CALL, START, CMD /C causes to enter and execute the first file and then the process to stop as the first file is finished. Use if errorlevel 1 if you have an older Windows than NT4/2000/XP to catch all errorlevels 1 and greater. In the calling batch file you can react using if errorlevel neq 0 Use: exit /B 1 # Or any other integer value in 0.255 You can also react on errorlevels after a call. If your batch files have spaces in their names, use quotes around the name: call "unit tests.bat"īy the way: if you do not have all the names of the batch files, you could also use for to do this (it does not guarantee the correct order of batch file calls it follows the order of the file system): FOR %x IN (*.bat) DO call "%x" Changing that behaviour without additional syntax would have broken many systems like batch menu systems (using batch files for menu structures).Īs in many cases with Microsoft, backward compatibility therefore is the reason for this behaviour. In the early days many batch files depended on the fact that calling a batch file would not return to the calling batch file. Obviously in later versions no other cmd shell was necessary anymore. Then the call command was introduced that called another cmd shell to execute the batch file and returned execution back to the calling cmd shell when finished. In ancient DOS versions it was not possible to recursively execute batch files. All the other answers are correct: use call.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |