[test.bat]
        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 [mailto:[EMAIL PROTECTED] 
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
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:

[test.bat]
         dir -xyz
         REM

[test.pl]
         `test.bat`;
         print("error is $?\n");

Running test.pl 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 
good).

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 runant.pl
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 runant.pl,
so 
that's fair. Still, I would expect runant.pl and ant.bat to behave as 
similar as possible. I.e. I'd expect both to support JAVA_HOME.

John



At 08:55 AM 3/11/2005, [EMAIL PROTECTED] 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. [mailto:[EMAIL PROTECTED]
> > 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: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to