I'm having some trouble using the system call in my ActiveState distribution of Perl (build 623). The system call seems to believe that its child process has finished when the child execs another command. Here's some illustrative code (saved to a file called 'test.pl'):

use strict; my $num = shift; if ($num) { if ($num % 2) { print "$num is calling system...\n"; system("perl test.pl " . ($num - 1)); print "$num is finished calling system.\n"; } else { print "$num is calling exec...\n"; exec("perl test.pl " . ($num - 1)); print "$num finished calling exec.\n"; } }
The program should be invoked with a number after it; the program then recursively calls itself with the next smaller number; using system for odds and exec for evens. On my Linux box, I get the following output:
$ perl test.pl 5 5 is calling system... 4 is calling exec... 3 is calling system... 2 is calling exec... 1 is calling system... 1 finished calling system. 3 finished calling system. 5 finished calling system.
which is exactly what I expect. I get this output when I try to call the same script on my Win2K machine:
D:\PerlCode>perl test.pl 5 5 is calling system... 4 is calling exec... 5 is finished calling system. 3 is calling system... D:\PerlCode>2 is calling exec... 3 is finished calling system. 1 is calling system... 1 is finished calling system.
D'oh! This is really messing up one of my programs, which is started by another program (through system) and has the power to update and restart itself (through exec); the parent program thinks that the child is done when it really just re-execed itself.

Is this a bug in the ActiveState distribution? Can anyone think of a good way to get around this?

Any help would be appreciated.

-Ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...


In reply to Trouble using system() on Win32 machines by ton

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.