Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3508 > unrolled thread

Popen to get stdout and stderr for ffmpeg - No such file or directory ?

Started bygoldtech <goldtech@worldpost.com>
First post2011-04-18 16:07 -0700
Last post2011-04-18 20:05 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Popen to get stdout and stderr for ffmpeg - No such file or directory ? goldtech <goldtech@worldpost.com> - 2011-04-18 16:07 -0700
    Re: Popen to get stdout and stderr for ffmpeg - No such file or directory ? "Rhodri James" <rhodri@wildebst.demon.co.uk> - 2011-04-19 00:35 +0100
    Re: Popen to get stdout and stderr for ffmpeg - No such file or directory ? Chris Rebert <clp2@rebertia.com> - 2011-04-18 16:36 -0700
      Re: Popen to get stdout and stderr for ffmpeg - No such file or directory ? goldtech <goldtech@worldpost.com> - 2011-04-18 20:05 -0700

#3508 — Popen to get stdout and stderr for ffmpeg - No such file or directory ?

Fromgoldtech <goldtech@worldpost.com>
Date2011-04-18 16:07 -0700
SubjectPopen to get stdout and stderr for ffmpeg - No such file or directory ?
Message-ID<8bb1fd96-91bf-42f6-a7ea-ab060cd22f66@a19g2000prj.googlegroups.com>
Hi,

Trying to learn how to run a linux command and get the stdout and
stderr. I'm trying the following:

>>> cmd3 = r'ffmpeg -i /home/giga/Desktop/Guitar1.flv'
>>> p = Popen(cmd3, stdout=PIPE, stderr=PIPE)

Traceback (most recent call last):
  File "<pyshell#73>", line 1, in <module>
    p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
  File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1141, in
_execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

But:

>>> if os.path.exists(r'/home/giga/Desktop/Guitar1.flv'):
	print "exist"

exist
>>>

And just running ffmpeg alone seems as expected:

>>> cmd2=r'ffmpeg'
>>> p = Popen(cmd2, stdout=PIPE, stderr=PIPE)
>>> stdout, stderr = p.communicate()
>>> stdout
'Hyper fast Audio and Video encoder\nusage: ffmpeg [options] [[infile
options] -i infile]... {[outfile options] outfile}...\n\n'
>>> stderr
"FFmpeg version git-N-29152-g0ba8485, Copyright (c) 2000-2011 the
FFmpeg developers\n  built on Apr 16 2011 16:40:56 with gcc 4.4.5\n
configuration: --enable-gpl ...snip...

Also if I run the exact command (cmd3) in the terminal it works OK.
Why is it not finding the file? Thanks, help appreciated.

[toc] | [next] | [standalone]


#3509

From"Rhodri James" <rhodri@wildebst.demon.co.uk>
Date2011-04-19 00:35 +0100
Message-ID<op.vt5qhz1za8ncjz@gnudebst>
In reply to#3508
On Tue, 19 Apr 2011 00:07:46 +0100, goldtech <goldtech@worldpost.com>  
wrote:

> Trying to learn how to run a linux command and get the stdout and
> stderr. I'm trying the following:
>
>>>> cmd3 = r'ffmpeg -i /home/giga/Desktop/Guitar1.flv'
>>>> p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
>
> Traceback (most recent call last):
>   File "<pyshell#73>", line 1, in <module>
>     p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
>   File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
>     errread, errwrite)
>   File "/usr/lib/python2.6/subprocess.py", line 1141, in
> _execute_child
>     raise child_exception
> OSError: [Errno 2] No such file or directory


This is something that catches everyone!  From the Fine Manual  
(http://docs.python.org/library/subprocess.html#using-the-subprocess-module):

> On Unix, with shell=False (default): In this case, the Popen class
> uses os.execvp() to execute the child program. args should normally
> be a sequence. If a string is specified for args, it will be used
> as the name or path of the program to execute; this will only work
> if the program is being given no arguments.

What you actually want is more like:

p = Popen(('ffmpeg', '-i', '/home/giga/Desktop/Guitar1.flv'),
           stdout=PIPE, stderr=PIPE)

The manual gives you an example of using shlex to split a string
into tokens if you'd rather do it that way.

-- 
Rhodri James *-* Wildebeest Herder to the Masses

[toc] | [prev] | [next] | [standalone]


#3510

FromChris Rebert <clp2@rebertia.com>
Date2011-04-18 16:36 -0700
Message-ID<mailman.530.1303169769.9059.python-list@python.org>
In reply to#3508
On Mon, Apr 18, 2011 at 4:07 PM, goldtech <goldtech@worldpost.com> wrote:
> Hi,
>
> Trying to learn how to run a linux command and get the stdout and
> stderr. I'm trying the following:
>
>>>> cmd3 = r'ffmpeg -i /home/giga/Desktop/Guitar1.flv'
>>>> p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
>
> Traceback (most recent call last):
>  File "<pyshell#73>", line 1, in <module>
>    p = Popen(cmd3, stdout=PIPE, stderr=PIPE)
>  File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
>    errread, errwrite)
>  File "/usr/lib/python2.6/subprocess.py", line 1141, in
> _execute_child
>    raise child_exception
> OSError: [Errno 2] No such file or directory
>
> But:
>
>>>> if os.path.exists(r'/home/giga/Desktop/Guitar1.flv'):
>        print "exist"
<snip>
> Also if I run the exact command (cmd3) in the terminal it works OK.
> Why is it not finding the file? Thanks, help appreciated.

Read The Fine Manual:
http://docs.python.org/library/subprocess.html#subprocess.Popen :
"On Unix, with shell=False (default): [...] If a string is specified
for args, it will be used as the name or path of the program to
execute; ***this will only work if the program is being given no
arguments.***" (emphasis added)

The system is interpreting the entire command string as the path to an
executable; obviously there's no directory named "ffmpeg -i ", so the
path is invalid, hence the error.

Try instead:
cmd3 = ['ffmpeg', '-i', '/home/giga/Desktop/Guitar1.flv']

Cheers,
Chris
--
http://blog.rebertia.com

[toc] | [prev] | [next] | [standalone]


#3523

Fromgoldtech <goldtech@worldpost.com>
Date2011-04-18 20:05 -0700
Message-ID<9c996aa8-8274-4aad-b473-29c63c8aba29@g7g2000pro.googlegroups.com>
In reply to#3510
> Read The Fine Manual:http://docs.python.org/library/subprocess.html#subprocess.Popen:

snip...
>
> Try instead:
> cmd3 = ['ffmpeg', '-i', '/home/giga/Desktop/Guitar1.flv']
>
> Cheers,
> Chris
> --http://blog.rebertia.com

No doubt, I should RTFM...you're right!

Yes, works like a charm now.

Thanks so much for the help. I really appreciate it!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web