Reputation: 1462
How do i make a batch
file to stop running other/next commands if first or any other command fails.
call grails clean
call grails compile
call grails package
call grails war
If grails clean
fail then grails compile
should not run and same with others.
Upvotes: 3
Views: 7794
Reputation: 41
The ERRORLEVEL
environment variable holds the return value of the last executed command.
So you can use:
IF %ERRORLEVEL% NEQ 0 (
echo "Previous command execution failed."
exit %ERRORLEVEL%
)
Please see http://steve-jansen.github.io/guides/windows-batch-scripting/part-3-return-codes.html for details.
Upvotes: 4