ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Cortell <>
Subject RE: launching Ant from a perl script
Date Fri, 11 Mar 2005 16:20:08 GMT
Sten, thanks for the added info. It seems putting an 'exit /b' at the end 
of ant.bat has the same effect as putting a 'goto: eof' which has the same 
effect as leaving ant.bat unmodified (sort of like putting a return 
statement at the end of a C/C++ function that returns void). Again, no 
surprise there.

So, it appears here's what's happening. Perl invokes a command shell to 
execute the bat file (ant.bat). The return code from that command shell 
process is NOT turning out to be %errorlevel%. So, while the ant 
application has failed, Perl never gets wind of it. Doing an 'exit' at the 
end of the bat apparently causes the command shell to return %errorlevel% 
as the return code. Without it, the command shell will return %errorlevel% 
if no other bat directive follows the failed ant app invocation (and even a 
simple REM statement can mask out the failure).

For proof of this latter point, try invoking the following:

         dir -xyz

         print("error is $?\n");

Running will print "error is 0" !! Take out the REM statement, and 
you'll get the expected behavior. Very strange. Put back the REM and add an 
'exit' and there too you'll get the expected behavior, although now 
test.bat will terminate the command window if you run it straight out (not 

Anyway, I realize some of this has strayed significantly from the focus of 
this mailing list. However, hopefully it does document why running ant.bat 
from a perl script is problematic (in so far as getting the success status 
of the ant invocation).

As to my previous email, I figured out why invoking ant via was 
having a problem finding tools.jar. Unlike ant.bat, tools.jar does NOT 
support JAVA_HOME. Instead, it relies on java.exe being in the PATH. (My 
PATH picks up an old java.exe)

The need for java.exe in the PATH is documented at the top of, so 
that's fair. Still, I would expect and ant.bat to behave as 
similar as possible. I.e. I'd expect both to support JAVA_HOME.


At 08:55 AM 3/11/2005, wrote:
> From the Windows XP on-line help:
>EXIT [/B] [exitCode]
>   /B          specifies to exit the current batch script instead of
>               CMD.EXE.  If executed from outside a batch script, it
>               will quit CMD.EXE
>   exitCode    specifies a numeric number.  if /B is specified, sets
>               ERRORLEVEL that number.  If quitting CMD.EXE, sets the
>               exit code with that number.
>Sten Rosendahl
> > -----Original Message-----
> > From: Dick, Brian E. []
> > Sent: Friday, March 11, 2005 4:35 PM
> > To: Ant Users List
> > Subject: RE: launching Ant from a perl script
> >
> > The "exit" command terminates the command shell and not the bat file.
> > You exit a bat file by "goto :eof".
>To unsubscribe, e-mail:
>For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message