Re: IPC::Open3 and output

2017-07-10 Thread Chas. Owens
I don't think I understand what you are saying. Neither provides data to
perl until you read from $file; however, it is important to note that the
results of the two functions are not the same.  The filehandle resulting
from the open contains both STDOUT and STDERR from the command (due to the
shell redirecting STDERR into STDOUT), but the filehandle resulting from
the open3 will only have the STDERR from the command.  This might have
something to do with the amount/timing of output available.

On Mon, Jul 10, 2017 at 10:09 AM Mike Martin  wrote:

> Thanks for that, now I have another issue.
> Unlike a piped open, open 3 does not seem to produce output immediately
>
> Is there any way to use pipes with open3 so that the FH has content before
> looping
> ie: this produces output
>
> my $pid=open($file, "-|","$cmd{$sopts->{subname}} 2>&1")
>
> while
> $pid=open3(undef,undef,$file,$cmdprog, @args)
>
> does not until you iterate over the FH
>
> thanks
>
>
>
>
>
> On 10 July 2017 at 07:13, Chas. Owens  wrote:
>
>> On Sun, Jul 9, 2017, 19:37 Mike Martin  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.)
>>
>>
>>
>
>


Re: IPC::Open3 and output

2017-07-10 Thread Mike Martin
Thanks for that, now I have another issue.
Unlike a piped open, open 3 does not seem to produce output immediately

Is there any way to use pipes with open3 so that the FH has content before
looping
ie: this produces output

my $pid=open($file, "-|","$cmd{$sopts->{subname}} 2>&1")

while
$pid=open3(undef,undef,$file,$cmdprog, @args)

does not until you iterate over the FH

thanks





On 10 July 2017 at 07:13, Chas. Owens  wrote:

> On Sun, Jul 9, 2017, 19:37 Mike Martin  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.)
>
>
>