CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Issue with Threads while collecting command output

 



pavan6754
New User

Nov 7, 2011, 8:23 AM

Post #1 of 2 (872 views)
Issue with Threads while collecting command output Can't Post

Hi Guys,

Below Program creates 3 Threads and each execute ls command for given input path .But this program hangs,seems to be issue with executing ls command.can you please help me out here.

(Note: i don't want to use here lock,as it will be sequential execution not parllel )


Code
use threads; 
use threads::shared;
my %hash:shared =1;
my @array=("c:\\Myscripts","c:\\Temp","c:\\Dropbox");
foreach(@array){
push @threads, threads->create(\&execute_ls, $_);
}
foreach (@threads) {
$_->join();
}
while(($key,$val)=each %hash){
print("$key:$val\n");
}
sub execute_ls{
my $ip=shift;
$hash{$ip}=`ls -1 $ip`;
}


Thanks in advance.


(This post was edited by pavan6754 on Nov 7, 2011, 8:42 AM)


rovf
Veteran

Nov 10, 2011, 2:15 AM

Post #2 of 2 (841 views)
Re: [pavan6754] Issue with Threads while collecting command output [In reply to] Can't Post


Quote
seems to be issue with executing ls


If you change execute_ls into


Code
$hash{$ip}=`CMD /c DIR $ip`;


does it still hang?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives