Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 45616 invoked from network); 11 Mar 2005 06:12:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 11 Mar 2005 06:12:02 -0000 Received: (qmail 16079 invoked by uid 500); 11 Mar 2005 06:12:00 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 15185 invoked by uid 500); 11 Mar 2005 06:11:57 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 15163 invoked by uid 99); 11 Mar 2005 06:11:57 -0000 X-ASF-Spam-Status: No, hits=0.4 required=10.0 tests=INVALID_DATE,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from fed1rmmtao08.cox.net (HELO fed1rmmtao08.cox.net) (68.230.241.31) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 10 Mar 2005 22:11:56 -0800 Received: from smtp.west.cox.net ([172.18.180.54]) by fed1rmmtao08.cox.net (InterMail vM.6.01.04.00 201-2131-118-20041027) with SMTP id <20050311061142.ILPF18934.fed1rmmtao08.cox.net@smtp.west.cox.net> for ; Fri, 11 Mar 2005 01:11:42 -0500 X-Mailer: Openwave WebEngine, version 2.8.15 (webedge20-101-1103-20040528) From: To: "Ant Users List" Subject: Re: Re: launching Ant from a perl script Date: Fri, 11 Mar 2005 1:11:44 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-Id: <20050311061142.ILPF18934.fed1rmmtao08.cox.net@smtp.west.cox.net> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 > Date: 2005/03/10 Thu PM 11:10:11 EST > To: "Ant Users List" > 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 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 > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional commands, e-mail: user-help@ant.apache.org