if(open($fh, "-|")){
while( < $fh > ){ $temp.= $_; }
close($fh);
open($fh, ">> /LogsEM/Log.txt");
flock($fh, 2);
print $fh "seg 1 ".$temp."\n";
flock($fh, 8);
close($fh);
}
exit;
####
open $fh, "-|";
####
my $pid = open $fh, "-|";
if ($pid) { # parent here. Read from child.
print "read from child: $_" while (<$fh>);
wait; # ...for the child to finish.
}
else { # child here. STDOUT connected to parent $fh
print while ;
exit; # important, you don't want the child to execute
# the statements after this block!
}
# parent continues ...