Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Popen to get stdout and stderr for ffmpeg - No such file or directory ?

Reply
Thread Tools

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

 
 
goldtech
Guest
Posts: n/a
 
      04-18-2011
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.
 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      04-18-2011
On Mon, Apr 18, 2011 at 4:07 PM, goldtech <> 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/subpr...bprocess.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
 
Reply With Quote
 
 
 
 
goldtech
Guest
Posts: n/a
 
      04-19-2011

> Read The Fine Manual:http://docs.python.org/library/subpr...process.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!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
subprocess.Popen and ordering writes to stdout and stderr Chris Withers Python 1 12-18-2009 06:57 PM
stdout and stderr to console and file simultaneously ids C Programming 4 04-14-2009 12:14 AM
IO.popen how to separate $stdout and $stderr Une Bévue Ruby 1 02-27-2008 12:52 AM
script hangs when run from command line and redirecting stdout and stderr to file it_says_BALLS_on_your forehead Perl Misc 2 01-10-2006 11:31 AM
status of redirecting STDOUT/STDERR to file jonathan Perl Misc 6 11-25-2003 12:58 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57