ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
Subject AW: Exec on Windows ignores return code?
Date Wed, 25 Apr 2007 06:11:04 GMT
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:chris.dudley@gmail.com] 
>Gesendet: Dienstag, 24. April 2007 19:30
>An: user@ant.apache.org
>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: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message