use strict; use Win32::Job; my @cmds = ( [ "netstat", 'netstat -na' ], [ $^X, 'perl -le "print\"pid=$$:Sleep 5 secs.\";sleep 5"' ], ); my $job = Win32::Job->new(); my @pids; my $i = 0; for my $cmd (@cmds) { ++$i; my $pid = $job->spawn($cmd->[0], $cmd->[1], { stdin => 'NUL', stdout => "$i.out", stderr => "$i.err" } ) or die "spawn: $^E"; push(@pids, $pid); } print "Processes pids: @pids are running...\n"; $job->run(60); # allow up to 60 seconds for all processes to end print "Job complete (output in files 1.out/1.err/2.out/2.err).\n"; my $stat = $job->status(); for my $pid (@pids) { exists($stat->{$pid}) or die "oops, no status for $pid"; my $rc = $stat->{$pid}->{exitcode}; my $t = $stat->{$pid}->{time}; print "pid=$pid, rc=$rc, elapsed time=$t->{elapsed} secs\n"; }