Multi argument open and STDERR

Paul Weaver paul.weaver at
Thu Oct 3 21:26:34 BST 2013

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,

Should do the trick, and if I do
        open(CMD, "-|", "ls", "-l", $file);
        while (<CMD>) {
                print "   TEST: $_\n";

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";

Obviously doesn't work, as 2>&1 is a bash redirection.

How can I capture STDERR?


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
Please note that the BBC monitors e-mails
sent or received.
Further communication will signify your consent to

More information about the mailing list