darronm (ukmay) wrote:
> I need to call an executable program multiple times and I
> will then need to process the returns to stdout.
> ...
> However as soon as I change the line above in sub1 to be:
> my @value = `vcover stats $FileName `;
> The script hangs.
Well, one problem I noted is that you're trying to use the old
'Thread' module. I tried something similar using 'threads',
and it worked fine:
#!/usr/bin/perl
use strict;
use warnings;
$| = 1;
use threads;
MAIN:
{
my @thr1 = threads->create(\&sub1, "ls -l /c");
my @thr2 = threads->create(\&sub1, "ls -l /var");
my @thr3 = threads->create(\&sub1, "ls -l /usr");
foreach my $thr (threads->list) {
my @output = $thr->join();
print("Thread returned:\n", @output, "\n");
}
}
exit(0);
### Subroutines ###
sub sub1 {
my $cmd = shift;
print "Command: $cmd\n";
my @output = `$cmd`;
return (@output);
}
# EOF