ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Christen" <...@active.ch>
Subject AW: <exec> problem with exit value
Date Sat, 24 Mar 2001 17:38:22 GMT
I've got a similar problem. Fact is, WindowsNT returns exit codes only from
within an executable. Batch and commands are not real executables. My
workaround was to modify the excute (I wraped it in an additional Task) in
the way, that the log methode scans the message and looks for a String EXIT
nn (nn would be the exitcode). You then must ensure, that at the end of the
command an "@ECHO EXIT %ERRORLEVEL%" (%ERRORLEVEL% represents your internal
stored errorcode), is inserted. If an EXIT nn has been detected by exec, it
sets an internal variable with the value (nn) and if the task has done its
work, checks again the exitcode scanned before ... Easy to implement but
somone might have a better solution.

Thomas

> -----Ursprüngliche Nachricht-----
> Von: Vincent Massol [mailto:vmassol@octo.fr]
> Gesendet am: Freitag, 23. März 2001 10:21
> An: ant-dev@jakarta.apache.org
> Betreff: <exec> problem with exit value
>
> Hi,
>
> I am trying to use the exec task to call another ant build file in some
> other directory (I don't want ot use the <ant> task to do that because I
> don't want to inherit any of the properties from the calling build.xml).
> However, when the called ant build file fails, the calling build file does
> not generate a "build failed" and does not stop.
>
> My settings :
>
> 1/ I have used the failonerror attribute in the exec task :
>
>         <exec dir="${out.sample.build.dir}" executable="ant.bat"
> failonerror="true">
>             <arg line="tests_all"/>
>         </exec>
>
> 2/ When I manually run the called ant build file it fails and if I type
> "echo %ERRORLEVEL%" at the DOS prompt (I am on Windows 2000), it correctly
> says "1"
>
> 3/ For confirmation, I modified the Ant Main.java class to output the exit
> value in the main() method and it effectively does a "System.Exit(1)"
>
> 4/ I modified Execute.waitFor() method as follows :
>
>     protected void waitFor(Process process) {
>         try {
>             process.waitFor();
>             System.out.println("Process return value = " +
> process.exitValue());
>             setExitValue(process.exitValue());
>         } catch (InterruptedException e) {}
>     }
>
> and it prints "Process return value = 0" !
>
> I am stuck ...
> Can you help me to debug this problem ?
>
> Thank you.
> Vincent.
>


Mime
View raw message