On Sun, Jul 9, 2017, 19:37 Mike Martin <redt...@gmail.com> wrote: > Hi > I am trying to use Open3 to capture stderr and avoiding the shell ie: > my $str="-v 35 -i /data/Downloads/testinput.mp4 -c:v libx264 -preset fast > -crf 28 -g 25 -c:a libmp3lame -b:a 128000 -threads 4 -af volume=2.5 -vf > scale='352:trunc(ow/((1/sar)*dar)/2)*2',fps='fps= 20',setsar='1/1' > -profile:a aac_he_v2 -strict -2 -y /home/mike/testopen.mp4"; > use Text::ParseWords; > @args = quotewords('\s+', "'", $str); > > use IPC::Open3; > > local(*HIS_IN, *HIS_OUT, *ERR); > my $cmd='ffmpeg'; > my $pid=open3(undef, undef, *ERR,$cmd, @args) or die print "$!"; > my $line; > > while (sysread ERR, $line, 256){ > print $line; > } > waitpid($pid, 0); > > However the output is buffered for around 2 minutes at a time rather > immediately being printed > > Is there any way around this >
Are you certain the buffering is in the read from ERR and not in the print? STDERR is not supposed to be buffered. Try adding $| = 1; Near the top of your program. That will turn off any buffering of the Perl 5 script's STDOUT. By default, Perl 5 will buffer STDOUT if it isn't writing to a pseudoterminal (eg if you are piping the output of the Perl 5 script to something else like tee.)