DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13655>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13655 proper retrncode for ant.bat Summary: proper retrncode for ant.bat Product: Ant Version: 1.5.1 Platform: PC OS/Version: Windows XP Status: NEW Severity: Enhancement Priority: Other Component: Wrapper scripts AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Hi Folks, I've been working with Ant 1.4.1 and Ant 1.5.1 so far. In one project we've used both wrappers the Windows wrapper "ant.bat" and the Unix wrapper "ant" from a third party tool that uses the returncodes of these scripts to determine if the build has succeeded. While this works out with the Unix wrapper we have had the problem that the Windows wrapper always returned 0 (which normally indicates success) also in case of Ant errors. To get around this I've added 6 lines of code to the Windows wrapper ant.bat. Key to this solution is the fact that command.exe generates a return code different to 0 if the last command executed has failed. So we first need to store the return code of the JVM call and execute a command that fails like dir "!!!not_existent!!!" which normally generates return code 1. I've used the same pattern to overwind the setlocal - endlocal boundary. I would appreciate if you take a look to my solution and tell me your opinion about it. Regards, Martin @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ START: changes to ant.bat 1.5.1: ('+' marks a line to be inserted) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ##################################################### ### CHANGE 1: introduce variable ANT_ERROR and initialize it to 0 ##################################################### *** ant.bat Wed Oct 2 10:55:10 2002 --- ant.cmd Tue Oct 15 17:23:24 2002 *************** *** 3,8 **** --- 3,10 ---- REM Copyright (c) 2001-2002 The Apache Software Foundation. All rights REM reserved. + set ANT_ERROR=0 + if exist "%HOME%\antrc_pre.bat" call "%HOME%\antrc_pre.bat" if "%OS%"=="Windows_NT" @setlocal *************** ##################################################### ### CHANGE 2: set ANT_ERROR to 1 if Ant has failed ##################################################### *** 77,86 **** --- 79,90 ---- :runAnt "%_JAVACMD%" -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" %ANT_OPTS% org.apache.tools.ant.Main %ANT_CMD_LINE_ARGS% + if not "%ERRORLEVEL%" == "0" set ANT_ERROR=1 goto end :runAntWithJikes "%_JAVACMD%" -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" "- Djikes.class.path=%JIKESPATH%" %ANT_OPTS% org.apache.tools.ant.Main % ANT_CMD_LINE_ARGS% + if not "%ERRORLEVEL%" == "0" set ANT_ERROR=1 goto end :end *************** ##################################################### ### CHANGE 3: lift ANT_ERROR over the setlocal - endlocal boundary ##################################################### ##################################################### ### CHANGE 4: return an errorcode <> 0 in case of Ant errors ##################################################### *** 88,95 **** --- 92,104 ---- set _JAVACMD= set ANT_CMD_LINE_ARGS= + if "%OS%"=="Windows_NT" set ERRORLEVEL=0 + if "%OS%"=="Windows_NT" ( if not "%ANT_ERROR%" == "0" dir "!!! not_existent!!!" >nul 2>&1 ) if "%OS%"=="Windows_NT" @endlocal + if "%OS%"=="Windows_NT" ( if not "%ERRORLEVEL%" == "0" set ANT_ERROR=1 ) :mainEnd if exist "%HOME%\antrc_post.bat" call "%HOME%\antrc_post.bat" + if not "%ANT_ERROR%" == "0" dir "!!!not_existent!!!" >nul 2>&1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END: changes to ant.bat @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ the above has been testet under Windows NT 4 and Windows XP -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
