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 08:07:40 GMT
Handling error codes is in the responsability of the shell. If the shell does not pass this
Ant cant do anything.

Just an idea ...
    <macrodef name="runBat">
        <attribute name="batch"/>
        <sequential>
            <echo file="runBat.bat">
                call @{batch}.bat
                if %ERRORLEVEL% echo %ERRORLEVEL% > @{batch}.err
            </echo>
            <delete file="runBat.bat"/>
        </sequential>
    </macrodef>
    <runBat batch="someBatch"/>
    <fail message="someBatch failed">
        <condition>
            <available file="someBatch.err"/>
        </condition>
    </fail>




Jan 

>-----Ursprüngliche Nachricht-----
>Von: Chris Dudley [mailto:chris.dudley@gmail.com] 
>Gesendet: Mittwoch, 25. April 2007 09:57
>An: Ant Users List
>Betreff: Re: Exec on Windows ignores return code?
>
>Removing the /B would just mean it would return 0 all the time.
>As it happens I can't actually modify the batch file (its one that
>ships with another product that I just happen to be invoking).
>I suppose I could use a wrapper batch file that caught the return code
>and then wrote a file out - but thats seems incredibly hacky!
>Is there no way for ANT to actually detect batch file return codes?
>
>Thanks for all the help by the way!
>
>On 4/25/07, Jan.Materne@rzf.fin-nrw.de 
><Jan.Materne@rzf.fin-nrw.de> wrote:
>> Modify your batch file so that it does not use the /B flag.
>>
>> Alternatively your batch could write a file as error marker 
>and your buildfile could check
>> that via <available>.
>>
>>
>> Jan
>>
>> >-----Ursprüngliche Nachricht-----
>> >Von: Chris Dudley [mailto:chris.dudley@gmail.com]
>> >Gesendet: Mittwoch, 25. April 2007 09:36
>> >An: Ant Users List
>> >Betreff: Re: Exec on Windows ignores return code?
>> >
>> >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, Jan.Materne@rzf.fin-nrw.de
>> ><Jan.Materne@rzf.fin-nrw.de> 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: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
>> >>
>> >>
>> >
>> 
>>---------------------------------------------------------------------
>> >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
>>
>>
>
>---------------------------------------------------------------------
>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