#! perl -slw use strict; use threads qw[ async ]; use threads::shared; sub runAndCheck { my( $cmd, $lookFor, $file, $checkRef, $doneRef ) = @_; open OUT, '>', $file or die "$file : $!"; open CMD, "$cmd |" or die "$cmd : $!"; while ( ) { $$checkRef = 1 if $_ =~ $lookFor; print OUT; } close CMD; close OUT; $$doneRef = 1; } my @cmds = map{ "dir $_" } qw[ c:\ P:\test r:\ d:\ ]; my @checks : shared = ( 0 ) x @cmds; my @dones : shared = ( 0 ) x @cmds; my $lookFor = 'junk.htm'; async{ runAndCheck( $cmds[ $_ ], $lookFor, "test$_.out", \$checks[ $_ ], \$dones[ $_ ] ); }->detach for 0 .. $#cmds; while( grep( $_, @dones ) < @cmds ) { sleep 1; for ( 0 .. $#cmds ) { if( $dones[ $_ ] == 1 ) { printf "'$cmds[ $_ ]' completed; '$lookFor' "; print $checks[ $_ ] ? 'was found' : 'was not found'; $dones[ $_ ] = 2; } } } __END__ P:\test>412014 'dir c:\' completed; 'junk.htm' was not found 'dir P:\test' completed; 'junk.htm' was found 'dir r:\' completed; 'junk.htm' was not found 'dir d:\' completed; 'junk.htm' was not found P:\test>412014 'dir c:\' completed; 'junk.htm' was not found 'dir r:\' completed; 'junk.htm' was not found 'dir d:\' completed; 'junk.htm' was not found 'dir P:\/s' completed; 'junk.htm' was found