From: Ben Morrow on

Quoth David Resnick <lndresnick(a)>:
> I need to execute multiple simultaneous system() statements. I
> originally did this using perl threads each invoking a system cmd,
> waiting for them to be joinable, then harvesting the return status
> with join(). The system commands are well behaved in that they will
> finish eventually (have built in time limits). Unfortunately, I
> discovered that the perl I need to use on some of our systems was
> built without threads and replacing it isn't an option.
> Is there a nice way to do this AND get the return values of the
> processes launched in single threaded perl? Repeated system("$cmd &")
> would execute all the processes, but I would need some way to get the
> return status. Fork and exec would also work, but same issue. I
> could run a wrapper that calls system and writes the result to a file
> I guess, but that feels clunky. Any suggestions that seem nicer?

Manual fork/exec is going to be easiest, but you need to do things in
the right order. For each process, fork in the parent and then exec in
the child. That way all the external processes are children of your
original process, so you can get all their exit statussesses with a loop
around wait or waitpid. (wait is easier, but only if there aren't going
to ever be any other children.)