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 18:43:10 GMT
That will produce the same unexpected result (the perl script's ?$ will be 
zero). exit /b simply sets the errorlevel, which is already non-zero. The 
problem is that the command shell process won't return errorlevel as a 
return code; the exit line itself is masking it out just as a REM statement 
does in the example I provided.

It appears the logic for the command shell is:
         - if exit is processed (with no /b on XP), return %errorlevel%
         - else, if last statement in bat file fails, return %errorlevel%
         - otherwise, return 0

In this case, 'exit /b 1' is the last statement and it does not fail, so 
zero is returned! Crazy.


At 11:34 AM 3/11/2005, Dick, Brian E. wrote:
>         dir test.bat
>         if not %errorlevel%==0 goto error_exit
>         :success_exit
>         exit /b 0
>         :error_exit
>         exit /b 1
>-----Original Message-----
>From: John Cortell []
>Sent: Friday, March 11, 2005 11:20 AM
>To: Ant Users List
>Subject: RE: launching Ant from a perl script
>Sten, thanks for the added info. It seems putting an 'exit /b' at the
>of ant.bat has the same effect as putting a 'goto: eof' which has the
>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
>end of the bat apparently causes the command shell to return
>as the return code. Without it, the command shell will return
>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
>          REM
>          `test.bat`;
>          print("error is $?\n");
>Running will print "error is 0" !! Take out the REM statement,
>you'll get the expected behavior. Very strange. Put back the REM and add
>'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
>Anyway, I realize some of this has strayed significantly from the focus
>this mailing list. However, hopefully it does document why running
>from a perl script is problematic (in so far as getting the success
>of the ant invocation).
>As to my previous email, I figured out why invoking ant via
>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,
>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
> >process
> >               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
> > > 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:
>To unsubscribe, e-mail:
>For additional commands, e-mail:

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

View raw message