I've been using
system(1,"cmd...") to run multiple system commands in parallel on Windows 2008 R2 using perl 5.8.3 but have also tried 5.8.8 with the same results.
My issue is acquiring the return code. If I setup a purposely bad command and just use
my $rc = system("cmd...") I get a proper error code returned. When I do the following:
my $pid = system(1,"cmd...");
do {
$wait = waitpid($pid,WNOHANG);
} while ($wait != -1);
This works just fine but after the process terminates and waitpid returns a -1 indicating it has terminated I can't find any way to get the return code from original system command. The waitpid command returns -1 once it terminates regardless of whether it terminated gracefully or not. I've tried using $? but it just returns -1 and even if it didn't I'm not sure how it would distinguish between the multiple processes running in parallel that can be terminating at any time.
Is there any way to retrieve the return code from the original system command, maybe by passing the PID? Is there a better way to do this that can both let me run multiple system commands in parallel on Windows and provide some error checking? Ultimately I just want to be able to output to the user which commands finished successfully and which errored.
Thanks for any help and please let me know if you need any more information or if I've left anything out.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.