Hm. I thought the setlocal/endlocal might be the problem too, but found out 
that's not the case. If you disable those lines in ant.bat, the behavior is the 
same. This sort of makes sense if you consider that errorlevel is a "special" 
variable--not truly an environment variable (notice it's not included if you 
type 'set' at the command line)

After playing around with this for quite some time, I think I stumbled on the 
solution. It appears it's as simple as adding an 'exit' at the end of ant.bat. 
Apparently, %errorlevel% isn't handled (returned) properly from the bat file 
unless there's an explicit exit. Maybe this is a bug. Who knows. I'm working on 
Windows XP, by the way. The behavior on other Windows variants may differ.

Thanks for the input.
John

> 
> From: Ronen Mashal <[EMAIL PROTECTED]>
> Date: 2005/03/10 Thu PM 11:10:11 EST
> To: "Ant Users List" <[email protected]>
> Subject: Re: launching Ant from a perl script
> 
> The problem is not that ant uses a .bat file, it is that the .bat file uses
> 'setlocal' and 'endlocal' statements which causes the system to restore old
> system values, including errorlevel !! Even if you try to call the ant.bat
> file from another .bat file, you'll get errorlevel set to its previous
> value, regardless of whether the build failed or not.
> To overcome this problem I check the log file for the 'BUILD SUCCESSFUL' or
> 'BUILD FAILED' messages. Here's the function:
> 
> sub CheckLogFile ()
> {
>    my $logFile = shift;
>    my $logContents;
> 
>    open (LOGFILE, "< $logFile") or die "Could not read log file
> $logFile\n";
>    read (LOGFILE, $logContents, -s $logFile);
>    close (LOGFILE);
> 
>    my $msg = "\n".("*" x 60)."\n";
>    my $fail = undef;
>    if ($logContents =~ /BUILD SUCCESSFUL\n(Total time: .*$)/) {
>       $msg .= "Build completed SUCCESSFULLY\n$1\n";
>    }
>    else {
>       $msg .= "BUILD FAILED\nSee details in $logFile\n";
>       $fail = 1;
>    }
>    $msg .= "".("*" x 60)."\n";
> 
>    if ($fail) {
>       die $msg;
>    }
> 
>    print $msg;
> }
> 
> Hope this helps.
> Ronen.
> 
> 
> John Cortell <[EMAIL PROTECTED]> wrote on 03/11/2005 02:52:33 AM:
> 
> > Hi,
> >
> > I'm having a tough time figuring out how to get the return code from an
> Ant
> > invocation when using perl. The problem is that the Ant front end is a
> .bat
> > file (I'm working on Windows). When you invoke a bat file from perl, and
> > that bat file in turn invokes  something else (the Java Ant application
> in
> > this case), perl does not capture the return code from that underlying
> > application.
> >
> > In case this is confusing, let me spell out exactly what's going on. If
> in
> > a perl file, I have the following:
> >
> >       `ant -xyz`;  # invalid invocation; will clearly fail
> >       print("error is $?\n");
> >
> > , when I run it, I get:
> >
> >     error is 0
> >
> > Surely, people are using Perl to drive Ant builds, so I'm sure there's a
> > simple answer to this, but I just can't find it.
> >
> > John
> >
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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