Multi argument open and STDERR

Dave Hodgkinson davehodg at gmail.com
Thu Oct 3 22:34:02 BST 2013


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.
> -----------------------------
> 



More information about the london.pm mailing list