Saturday, April 6, 2013

How to check the status of call command in dos batch file

echo  1.Building all four project.
call apacheant\bin\ant -buildfile build-all.xml >logfile.txt
findstr "succeed" logfile.txt >nul
if errorlevel 1 (echo Build failed) else (echo Build Succeeded)
 
Naturally, the echo ... could be replaced by 'set antstatus=SUCCEED` if required.
Don't try to use ERRORLEVEL to control the processing since MANY commands will change ERRORLEVEL to report their own status.

It may also be possible that ANT returns a status on termination. You could check with
echo %errorlevel%
 
after the ant step. If it returns an errorlevel, then you don't need to create and interpret the logfile.
The IF ERRORLEVEL syntax is

if errorlevel n Command_if_errorlevel_is_n_OR_GREATER_THAN_n

No comments:

Post a Comment