Hi,
I'm working on a multi platform test script that needs to be able to run on windows, and system() doesn't seem to be correctly passing the return value from ant. To demonstrate I've made this simple script. If it's run from within a directory that contains build.xml it will pass. If not it will fail. In both cases perl is claiming the return value to be 0. But if I just run "ant clean" directly from the command line then check the return code in the windows system var it isn't 0 in the failing case. It is 1. Oddly I've tried the same perl code with windows commands like DIR in known passing and known failing ways and in that case the system() call is returning the error code faithfully. I'm not sure in this case whether it's an ant issue or a perl issue. Might there be any other way to do this that would be more reliable?
#!/usr/bin/perl -w
use warnings;
use strict;
use POSIX;
my $command = "ant clean";
my $return = system ($command);
print "RETURN VALUE: $return\n";
print "CHILD_ERROR_NATIVE: ${^CHILD_ERROR_NATIVE}\n";
####OUTPUT######
#PASSING CASE
c:\BUILD_DIRECTORY>perl test.pl
Buildfile: build.xml
Trying to override old definition of task javac
clean:
BUILD SUCCESSFUL
Total time: 0 seconds
RETURN VALUE: 0
CHILD_ERROR_NATIVE: 0
c:\BUILD_DIRECTORY>ant clean
Buildfile: build.xml
Trying to override old definition of task javac
clean:
BUILD SUCCESSFUL
Total time: 0 seconds
c:\BUILD_DIRECTORY>echo %ERRORLEVEL%
0 <-------------------------------
# FAILING CASE
c:\NOT_BUILD_DIRECTORY>perl jet\test.pl
Buildfile: build.xml does not exist!
Build failed
RETURN VALUE: 0
CHILD_ERROR_NATIVE: 0
c:\NOT_BUILD_DIRECTORY>ant clean
Buildfile: build.xml does not exist!
Build failed
c:\NOT_BUILD_DIRECTORY>echo %ERRORLEVEL%
1 <-------------------------