ericaQA has asked for the wisdom of the Perl Monks concerning the following question:
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 <-------------------------
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: system call returns incorrect in windows
by Lotus1 (Vicar) on Apr 07, 2018 at 01:49 UTC | |
|
Re: system call returns incorrect in windows
by ikegami (Patriarch) on Apr 06, 2018 at 18:15 UTC | |
by ericaQA (Novice) on Apr 06, 2018 at 18:59 UTC | |
|
Re: system call returns incorrect in windows
by Anonymous Monk on Apr 06, 2018 at 21:15 UTC | |
|
Re: system call returns incorrect in windows
by Anonymous Monk on Apr 06, 2018 at 21:16 UTC | |
by ericaQA (Novice) on Apr 06, 2018 at 22:56 UTC | |
by Anonymous Monk on Apr 07, 2018 at 03:31 UTC | |
by Lotus1 (Vicar) on Apr 07, 2018 at 18:46 UTC | |
by Anonymous Monk on Apr 08, 2018 at 05:28 UTC |