in reply to Re^2: Getting a return code from waitpid in Windows
in thread Getting a return code from waitpid in Windows

I may have answered my own question... I still can't figure out how to get it to work with waitpid but it does work properly when using just plain "wait". The reason I wasn't doing that before is that it is a blocking call so it prevents me from looping through checking each PID I kicked off previously. However, it seems that it blocks until any of the processes returns. The wait call itself returns the PID that just terminated and just after $? returns the status. So presumably I can collect all my PIDs as I kick them off then loop through on a blocking wait one by one waiting for each of those PIDs to terminate and collect the status as they do.

The following seems to do what I want:

my $pid1Complete = 0; my $pid2Complete = 0; my $pid3Complete = 0; my $pid1 = system(1,"cmd..."); my $pid2 = system(1,"cmd..."); my $pid3 = system(1,"cmd..."); my $finishingPID = 0; do { $finishingPID = wait(); $rc = $?; if ($finishingPID == $pid1) { $pid1Complete = 1; print "PID1 finished with return code $rc\n"; } elsif ($finishingPID == $pid2) { $pid2Complete = 1; print "PID2 finished with return code $rc\n"; } elsif ($finishingPID == $pid3) { $pid3Complete = 1; print "PID3 finished with return code $rc\n"; } } while (($pid1Complete == 0) || ($pid2Complete == 0) || ($pid3Complet +e == 0));


If anybody has any suggestions for improvements or other ideas I'd be happy to hear them.

Thanks again.