#! perl -slw use strict; use threads qw[ async ]; use threads::shared; our $DRIVES ||= 'C'; die "Nothing to search for" unless $ARGV[ 0 ]; sub runAndCheck { my( $cmd, $foundRef, $doneRef, $lookfor ) = @_; my $pid = open CMD, "$cmd |" or die "$cmd : $!"; while ( my $line = ) { chomp $line; last if keys %$lookfor == grep defined, values %$lookfor; $line =~ $_ and $lookfor->{ $_ } = $line for keys %{ $lookfor }; } close CMD; kill 1, $pid; $$doneRef = 1; } my @cmds = map{ "attrib /s $_:\\* " } split '', $DRIVES; my @found : shared; my @dones : shared = ( 0 ) x @cmds; my %lookfor: shared; @lookfor{ @ARGV } = (); async{ runAndCheck( $cmds[ $_ ], \@found, \$dones[ $_ ], \%lookfor ); }->detach for 0 .. $#cmds; sleep 1 while grep( $_, @dones ) < @cmds; if( grep defined, %lookfor ) { printf "%20s : %s\n", $_, defined $lookfor{ $_ } ? " was found at '$lookfor{ $_ }'" : " was not found." for keys %lookfor; } else { print "None of @ARGV were found"; } #### P:\test>412014 -DRIVES=CDPR junk\.htm$ 412014 copyrght \bcmd\.exe CMD\.EXE junk\.htm$ : was found at 'A C:\Perl\test\junk.htm' \bcmd\.exe : was not found. copyrght : was found at ' R R:\copyrght.htm' 412014 : was found at 'A C:\Perl\test\412014.pl' CMD\.EXE : was found at 'A C:\WINDOWS\SYSTEM32\CMD.EXE' P:\test>412014 -DRIVES=PDR junk\.htm$ 412014 copyrght \bcmd\.exe CMD\.EXE junk\.htm$ : was found at 'A P:\test\junk.htm' \bcmd\.exe : was not found. copyrght : was found at ' R R:\copyrght.htm' 412014 : was found at 'A P:\test\412014.pl' CMD\.EXE : was not found. P:\test>412014 -DRIVES=PDR junk\.htm$ 412014 copyrght cmd\.exe CMD\.EXE cmd\.exe : was not found. junk\.htm$ : was found at 'A P:\test\junk.htm' copyrght : was found at ' R R:\copyrght.htm' 412014 : was found at 'A P:\test\412014.pl' CMD\.EXE : was not found. P:\test>412014 junk\.htm$ 412014 copyrght cmd\.exe CMD\.EXE cmd\.exe : was found at 'A C:\Program Files\Classic PhoneTools\inssuitecmd.exe' junk\.htm$ : was found at 'A C:\Perl\test\junk.htm' copyrght : was not found. 412014 : was found at 'A C:\Perl\test\412014.pl' CMD\.EXE : was found at 'A C:\WINDOWS\SYSTEM32\CMD.EXE'