ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ronen Mashal <ro...@jacada.com>
Subject Re: launching Ant from a perl script
Date Fri, 11 Mar 2005 04:10:11 GMT
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 <cortell@cox.net> 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: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message