I use IPC::Run to get output from an external executable in a cron run script. I need it to be able to filter and make decisions based on the output on the fly. But the problem is it gives me output not on the fly, but in few batches - many lines at once, only after the executable has been run for a while. Is it possible to somehow flush the output like we can on the grep command with grep --line-buffered
? I do not see this properly answered in all the Perl sites. Here is my script part:
use IPC::Run qw( start pump finish );
...
my $externalExecRun = start \@executableAndParameters, \undef, \$executableStdout, \$executableStderr ;
while (42) {
pump $externalExecRun;
if ($executableStdout eq '' and $engineStderr eq '') {last;}
WriteToLog("\$executableStdout: -->$executableStdout<--"); #This writes many lines at once
WriteToLog("\$executableStderr: -->$executableStderr<--");
$executableStdout = "";
$executableStderr = "";
}
finish $externalExecRun;