So how can I get ANT to detect when the batch file goes bang? I tried getting ANT to invoke the batch file direct instead of invoking cmd /c test.bat and that made no difference.
ANT invokes a bash shell on unix and then runs a shell script in that and yet return codes work there, just not on Windows. On 4/25/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Works for me, BUT you must not use the /B in your batch file. Have a look at the help with "help exit" - /B just sets the error code for the _batchfile_, but Ant is not executing the batchfile. Ant executes the shell! Jan >-----Ursprüngliche Nachricht----- >Von: Chris Dudley [mailto:[EMAIL PROTECTED] >Gesendet: Dienstag, 24. April 2007 19:30 >An: [email protected] >Betreff: Exec on Windows ignores return code? > >Apologies if this is a FAQ or a known problem but I couldn't find >anything useful in the archives, google or in bugzilla. > >I am having trouble with the exec task on Windows. >It seems to me that regardless of what the executable returns, ANT >always claims the return code on Windows is 0. > >The code below runs a simple test batch file. The batch file is >hardcoded to always return 1. Running the batch file from a command >prompt and then echoing %ERRORLEVEL% does indeed show the return code >to be 1 and not 0. > >So where is ANT getting the 0 return code from? > >I have tried a similar test on Linux and UNIX (not using a batch >script of course) and it works perfectly. > >But yet I don't think this is a peculiarity of Windows since >%ERRORLEVEL% is being set correctly - ANT just isn't picking it up. > >I have tried ANT 1.6.2, 1.6.5 and 1.7.0 - all seem to exhibit the same >behaviour. > >I am hoping there is a workaround or a simple solution to something >stupid I've done! > >Thanks! > >This is the ANT snippet: > ><property name="test.dir" value="c:\install"/> ><exec executable="cmd" failonerror="true" resultproperty="error" > ><arg line="/c ${test.dir}\test.bat"/> ></exec> ><echo message="error=${error}"/> > >test.bat contains just one line: > >exit /B 1 > >This is what comes out when ant is run with debug on: > > [exec] Current OS is Windows XP > [exec] Executing 'cmd' with arguments: > [exec] '/c' > [exec] 'C:\install\test.bat' > [exec] > [exec] The ' characters around the executable and arguments are > [exec] not part of the command. >Execute:Java13CommandLauncher: Executing 'cmd' with arguments: >'/c' >'C:\install\test.bat' > >The ' characters around the executable and arguments are >not part of the command. > [exec] > [exec] C:\>exit /B 1 >Setting project property: error -> 0 > [echo] error=0 > >I really want ANT to abort the build if the executable returns >non-zero, which works fine on UNIX but I need it to work on Windows >too. > >Any ideas please? > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
