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 <-------------------------

In reply to system call returns incorrect in windows by ericaQA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.