Multi argument open and STDERR

Paul Weaver paul.weaver at bbc.co.uk
Fri Oct 4 16:09:20 BST 2013


Thanks, that did the job very nicely, and exists as a package in ubuntu, which makes it far easier than converting a cpan one.

ffmpeg does tend to be very vague with documentation, we actually use a fork called ffmbc, but same principle.

ffprobe can do things in a more structured way, but I do like ffmpeg, as if it detects the duration, I know I'll be able to convert it, and the code already ran it so there was no need to do anything further down in the unreadable mess my code tends to land in.


________________________________________
From: london.pm-bounces at london.pm.org [london.pm-bounces at london.pm.org] on behalf of Dave Hodgkinson [davehodg at gmail.com]
Sent: 03 October 2013 22:34
To: London.pm Perl M[ou]ngers
Subject: Re: Multi argument open and STDERR

Capture::Tiny just did the job for me today. Screw line noise.

Sent from my iPhone

> On 3 Oct 2013, at 21:26, Paul Weaver <paul.weaver at bbc.co.uk> wrote:
>
> I have a program that needs to run an external program (ffmpeg)
>
> I do this by running
>
> my $cmd = "$FFMPEG -i '$file' 2>&1|"
> open(CMD, $cmd); while (<CMD>) { #blah } ; close(CMD);
>
> This works fine. Until there's a single quote in the filename.
>
> Reading the docs,
> open FILEHANDLE,MODE,EXPR,LIST
>
> Should do the trick, and if I do
>        open(CMD, "-|", "ls", "-l", $file);
>        while (<CMD>) {
>                print "   TEST: $_\n";
>        }
>        close(CMD);
>
> It works fine.
>
> The trouble is, ffmpeg outputs the -i information on STDERR, not STDOUT.
>
>        open(CMD, "-|", "ffmpeg", "-i", $file, "2>&1");
>        while (<CMD>) {
>                print "   TEST: $_\n";
>        }
>        close(CMD);
>
> Obviously doesn't work, as 2>&1 is a bash redirection.
>
> How can I capture STDERR?
>
> Thanks
>
>
> -----------------------------
> http://www.bbc.co.uk
> This e-mail (and any attachments) is confidential and
> may contain personal views which are not the views of the BBC unless specifically stated.
> If you have received it in
> error, please delete it from your system.
> Do not use, copy or disclose the
> information in any way nor act in reliance on it and notify the sender
> immediately.
> Please note that the BBC monitors e-mails
> sent or received.
> Further communication will signify your consent to
> this.
> -----------------------------
>



-----------------------------
http://www.bbc.co.uk
This e-mail (and any attachments) is confidential and
may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in
error, please delete it from your system.
Do not use, copy or disclose the
information in any way nor act in reliance on it and notify the sender
immediately.
Please note that the BBC monitors e-mails
sent or received.
Further communication will signify your consent to
this.
-----------------------------



More information about the london.pm mailing list