I have a batch file that’s calling the same executable over and over with different parameters. How do I make it terminate immediately if one of the calls returns an error code of any level?
Basically, I want the equivalent of MSBuild’s ContinueOnError=false.
Check the
errorlevelin anifstatement, and thenexit /b(exit the batch file only, not the entire cmd.exe process) for values other than 0.If you want the value of the errorlevel to propagate outside of your batch file
but if this is inside a
forit gets a bit tricky. You’ll need something more like:Edit: You have to check the error after each command. There’s no global ‘on error goto’ type of construct in cmd.exe/command.com batch. I’ve also updated my code per CodeMonkey, although I’ve never encountered a negative errorlevel in any of my batch-hacking on XP or Vista.