T
Tim
O.K., I'm starting to lose it. I've read a lot of threads on this list
regarding forking processes on Windows. I'm still having problems even
with the info I have found. I'm asking for some direction.
I am trying to spawn several children processes and execute a the same
command on each child. I want to reap (read) the results of each of
these children and wait for each to end in their own order. The
command I am executing can potentially sent out a lot of output. I
execute the command using backticks (`) in order to get the output.
The following perl code will work to a certain extent on *NIX platorms
but will lockup / hang on Windows (XP to be specific). It appears to
have the problem with the pipe but I'm not entirely sure what's going
on. I am using the latest Acitvestate perl.
Bottom line... does anyone have a chunk of perl that demonstrates what
I'm trying to do but may be more robust in the Windows environment. If
you can help me figure this out I will sing your praises while dancing
in my cube. Thanks - Tim
### snippet that need rewriting / robustifying ###
$cmd = "p4 -p mymachine.com:50720 -c client3 info";
my $nchildren = 7;
my ($active, $ichild, $pid, @rfhs, $rfh);
$active = 0;
for( $ichild = $nchildren; $ichild > 0; $ichild-- )
{
pipe RFH, WFH;
if( $pid = fork ) {
print "Forked pid $pid.\n";
open $rfhs{ $pid }, "<&RFH";
close WFH;
$active++;
} elsif( defined $pid ) {
close RFH;
print WFH `$cmd 2>&1`;
close WFH;
exit;
} else {
print "fork failed!\n";
exit 1;
}
}
while( $active > 0 ) {
$pid = wait;
$rfh = $rfhs{ $pid };
print "\n$pid completed. It's output is:\n", <$rfh>;
close $rfh;
$active--;
}
regarding forking processes on Windows. I'm still having problems even
with the info I have found. I'm asking for some direction.
I am trying to spawn several children processes and execute a the same
command on each child. I want to reap (read) the results of each of
these children and wait for each to end in their own order. The
command I am executing can potentially sent out a lot of output. I
execute the command using backticks (`) in order to get the output.
The following perl code will work to a certain extent on *NIX platorms
but will lockup / hang on Windows (XP to be specific). It appears to
have the problem with the pipe but I'm not entirely sure what's going
on. I am using the latest Acitvestate perl.
Bottom line... does anyone have a chunk of perl that demonstrates what
I'm trying to do but may be more robust in the Windows environment. If
you can help me figure this out I will sing your praises while dancing
in my cube. Thanks - Tim
### snippet that need rewriting / robustifying ###
$cmd = "p4 -p mymachine.com:50720 -c client3 info";
my $nchildren = 7;
my ($active, $ichild, $pid, @rfhs, $rfh);
$active = 0;
for( $ichild = $nchildren; $ichild > 0; $ichild-- )
{
pipe RFH, WFH;
if( $pid = fork ) {
print "Forked pid $pid.\n";
open $rfhs{ $pid }, "<&RFH";
close WFH;
$active++;
} elsif( defined $pid ) {
close RFH;
print WFH `$cmd 2>&1`;
close WFH;
exit;
} else {
print "fork failed!\n";
exit 1;
}
}
while( $active > 0 ) {
$pid = wait;
$rfh = $rfhs{ $pid };
print "\n$pid completed. It's output is:\n", <$rfh>;
close $rfh;
$active--;
}