I have a nice progress indicator from Need a progress indicator for a Perl system() command using T:R:G mod
open(my $cmd, '-|', "$command $flags_args 2>/dev/null")
or print "\nAttention: Command $command $flags_args failed $!"
and return 1;
while (<$cmd>)
{
$percentage = ($cntr/$lines) * 100;
$percentage = 100 if $percentage > 100;
printf("Progress: %3d%%\r", $percentage);
$cntr++;
}
close($cmd);
Now my I want logging of the STDOUT and STDERR of the commands output. I'm not too familiar with pipe output so I tried adding:
print $LOG $cmd
and
print $LOG Dumper(\$cmd)
before the end of the while loop. It did not work. The first output
GLOB(0x11df7a0)GLOB(0x11df7a0)GLOB(0x11df7a0)
the second
$VAR1 = \\*{'::$cmd'};
$VAR1 = \\*{'::$cmd'};
$VAR1 = \\*{'::$cmd'};
Does anyone know how I can get the output from the piped $cmd? Example for a $command = make command
Making all in src
make[1]: Entering directory `/tmp'
Making all in include
make[2]: Entering directory '/tmp/2'
...