Stop batch script from executing while encountering error
Solution 1
"Check the errorlevel in an if statement, and then exit /b (exit the batch file only, not the entire cmd.exe process) for values of 1 or greater."
if %errorlevel% neq 0 exit /b %errorlevel%
Look here for details: How do I make a batch file terminate upon encountering an error?
Solution 2
The correct syntax for stopping execution if error is:
if ERRORLEVEL 1 exit
Admin
Updated on June 27, 2022Comments
-
Admin almost 2 years
So I'm building multiple client using the same batch script. If there's an error while building one, that process simply stops and continues with the next one. Because there's a lot of output on the screen and I'm doing other things, most of the time I miss that there was a build error.
Is there a way to stop executing the following tasks if there's an error, and show a popup message to get my attention? Or at least stop executing so when I come back to the command window I can see that there was a failure?
@echo off if "%1"=="?" GOTO HELP if NOT "%1"=="" set rev=%1 if NOT "%2"=="" set version=%2 @echo on rem build one call perl buildClient.pl -brandName="myBrand" -group="group1" rem build two call perl buildClient.pl -brandName="myBrand" -group="group2" rem build three call perl buildClient.pl -brandName="myBrand" -group="group3" rem build four call perl buildClient.pl -brandName="myBrand" -group="group4" @echo off goto EXIT :HELP cls echo. echo. echo usage: buildbrand.bat [revision] [version] [group] echo. echo ? = this help screen echo. echo revision = build version echo Example: 5.2.31 echo group = group of phones or phone name echo Example: SonyEricsson\K750 echo. :EXIT set version= set rev= set brandName= PAUSE