You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Michaël Smith <ne...@hotmail.com> on 2001/02/01 16:49:19 UTC

Possible bug with failonerror attribute of exec task

I believe I have found a bug with the failonerror attribute of the exec 
task.  Here is part of my build.xml:

   <target name="test">
        <echo message=""/>
        <echo message="-- Building and executing tests:"/>
        <echo message=""/>
        <exec dir="../../../${project.vob}/${project.name}/build" 
executable="test.bat" os="Windows 2000" failonerror="True"/>
    </target>

For the failonerror I tried "true" "True" "yes" "Yes".  I'm not sure which 
is correct because it's not documented.  Here is my batch file:

dir asdf
echo errorlevel = %ERRORLEVEL%

This always has errorlevel = 1.

Finally the output of my build:

Ant version 1.2 compiled on October 24 2000

Buildfile: build.xml
Detected Java Version: 1.3
Detected OS: Windows 2000
Project base dir set to: Z:\Common\catapult\bin
Build sequence for target `test' is [test]
Complete build sequence is [test, init, shutdown_test_environment, tests, 
build_tar, deploy_tar, init_test_environment, clean, usage, label, build]

-- Building and executing tests:

     [exec] Myos = Windows 2000
     [exec] test.bat
     [exec]
     [exec] Fichier introuvable
     [exec] Z:\customer_registry\customer\build>dir asdf
     [exec]  Le volume dans le lecteur Z s'appelle CCase
     [exec]  Le num&#8218;ro de s&#8218;rie du volume est 0234-5789
     [exec]
     [exec]  R&#8218;pertoire de Z:\customer_registry\customer\build
     [exec]
     [exec]
     [exec] Z:\customer_registry\customer\build>echo errorlevel = 1
     [exec] errorlevel = 1

BUILD SUCCESSFUL

Total time: 1 second

Michaël

_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.


Re: Possible bug with failonerror attribute of exec task

Posted by Bill Burton <bi...@progress.com>.
Hello,

Running under Ant 1.2 and a recent 1.3alpha with the following batch file
on Windows 4.0 SP5:

fail.bat:
@echo off
dir xxx

The following build file exectest.xml:
<!-- Tests running an executable file/script -->
<project name="ExecTest" basedir="." default="main">
  <property name="exec" value="dir"/>
  <property name="arg" value=""/>
  <target name="main">
    <exec executable="${exec}" failonerror="true">
      <arg line="${arg}"/>
    </exec>
  </target>
</project>

Returns the following:

D:\Work\anttest>ant -f exectest.xml -Dexec=fail.bat
Buildfile: exectest.xml

main:
     [exec]  Volume in drive D has no label.
     [exec]  Volume Serial Number is E8BD-8AE3
     [exec]
     [exec]  Directory of D:\Work\anttest
     [exec]
     [exec] File Not Found

BUILD FAILED

D:\Work\anttest\exectest.xml:6: Exec returned: 2

Total time: 2 seconds

I tried using a JavaSoft JDK 1.2.2_007 and 1.3.0-C with the same results.

So, I'm unable to reproduce any kind of a bug.  As you can see, Ant gets
the result of the batch file errorlevel.  In my case, I don't have any
other commands after the command causing the error.  

Then I added: echo ERRORLEVEL=%ERRORLEVEL% to the end of the batch file
and the build stopped failing.  The real bug it appears is in your batch
file.  Don't have any other commands after the command that could cause
the error you're interested in.  Even a REM or ECHO command will change
the exit status!!!  Note that I said "exit status" and not errorlevel.  It
appears the exit status of a program is copied to errorlevel.  However,
when the batch file exits it uses the exit status NOT errorlevel.  Looks
like a bug in cmd.exe to me.

-Bill Burton

Michaël Smith wrote:
> 
> I believe I have found a bug with the failonerror attribute of the exec
> task.  Here is part of my build.xml:
> 
>    <target name="test">
>         <echo message=""/>
>         <echo message="-- Building and executing tests:"/>
>         <echo message=""/>
>         <exec dir="../../../${project.vob}/${project.name}/build"
> executable="test.bat" os="Windows 2000" failonerror="True"/>
>     </target>
> 
> For the failonerror I tried "true" "True" "yes" "Yes".  I'm not sure which
> is correct because it's not documented.  Here is my batch file:
> 
> dir asdf
> echo errorlevel = %ERRORLEVEL%
> 
> This always has errorlevel = 1.
> 
> Finally the output of my build:
> 
> Ant version 1.2 compiled on October 24 2000
> 
> Buildfile: build.xml
> Detected Java Version: 1.3
> Detected OS: Windows 2000
> Project base dir set to: Z:\Common\catapult\bin
> Build sequence for target `test' is [test]
> Complete build sequence is [test, init, shutdown_test_environment, tests,
> build_tar, deploy_tar, init_test_environment, clean, usage, label, build]
> 
> -- Building and executing tests:
> 
>      [exec] Myos = Windows 2000
>      [exec] test.bat
>      [exec]
>      [exec] Fichier introuvable
>      [exec] Z:\customer_registry\customer\build>dir asdf
>      [exec]  Le volume dans le lecteur Z s'appelle CCase
>      [exec]  Le num&#8218;ro de s&#8218;rie du volume est 0234-5789
>      [exec]
>      [exec]  R&#8218;pertoire de Z:\customer_registry\customer\build
>      [exec]
>      [exec]
>      [exec] Z:\customer_registry\customer\build>echo errorlevel = 1
>      [exec] errorlevel = 1
> 
> BUILD SUCCESSFUL
> 
> Total time: 1 second
> 
> Michaël