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.