And when I find "serious.txt", Is there a way I can immediatly stop all the other threads from completing?

By that I assume you to mean that you want searching to cease once you have found something that matches all your targets.

NOTE: As coded, the things to search for are themselves used as regex. As such, you need to escape any meta characters on the command line. It is also case sensitive. I consider these a bonus for the application shown, but you may wan't to change one or the other.

#! 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 = <CMD> ) { 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"; }

Some examples runs:

P:\test>412014 -DRIVES=CDPR junk\.htm$ 412014 copyrght \bcmd\.exe CM +D\.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.p +l' CMD\.EXE : was found at 'A C:\WINDOWS\SYSTEM32\C +MD.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\Clas +sic 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.p +l' CMD\.EXE : was found at 'A C:\WINDOWS\SYSTEM32\C +MD.EXE'

Examine what is said, not who speaks.        The end of an era!
"But you should never overestimate the ingenuity of the sceptics to come up with a counter-argument." -Myles Allen
"Think for yourself!" - Abigail        "Time is a poor substitute for thought"--theorbtwo         "Efficiency is intelligent laziness." -David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re^3: question about running a system and a perl function background by BrowserUk
in thread question about running a system and a perl function background by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.