I'm encountering an issue with the <exec> task on batch files in my NAnt project files. When running on Windows XP SP 3 (but not Windows Vista or Windows Server 2008) and using NAnt 0.85 or 0.91alpha2, the <exec> task will always succeed (returning an error code of 0) regardless of what the executed script returned.
As an example, I wrote the following NAnt target:
<target name="build">
<exec program="fail.bat"
failonerror="false" resultproperty="makeall.result">
</exec>
<echo message="Makeall task returned result ${makeall.result}"/>
<fail if="${int::parse(makeall.result) != 0}">Encountered ${makeall.result} errors.</fail>
</target>
which calls the following batch file:
exit /b 1
Under normal operation (Windows Vista), the result of running NAnt is:
build:
[exec] C:\Users\Will\Code>exit /b 1
[exec] C:\Users\Will\Code\fail.build(6,4):
[exec] External Program Failed: C:\Users\Will\Code\fail.bat (return code was 1)
[echo] Makeall task returned result 1
BUILD FAILED - 1 non-fatal error(s), 0 warning(s)
But on two different Windows XP SP3 machines, the result of running NAnt is:
build:
[exec] C:\Documents and Settings\Will\My Documents\My Code>exit /b 1
[echo] Makeall task returned result 0
BUILD SUCCEEDED
Although I'm not discounting the possibility that this is a bug, I find it much more likely that I'm forgetting some crucial configuration setting on either Windows or NAnt that is causing this behavior. Has anyone else encountered this? Is there a reasonably elegant workaround?