Any way to assign terminal output to variable with python?

Posted by Gordon Fontenot on Stack Overflow See other posts from Stack Overflow or by Gordon Fontenot
Published on 2010-03-15T17:49:08Z Indexed on 2010/03/15 17:49 UTC
Read the original article Hit count: 156

Filed under:
|
|
|

I need to grab the duration of a video file via python as part of a larger script. I know I can use ffmpeg to grab the duration, but I need to be able to save that output as a variable back in python. I thought this would work, but it's giving me a value of 0:

cmd = 'ffmpeg -i %s 2>&1 | grep "Duration" | cut -d \' \' -f 4 | sed s/,//' % ("Video.mov")
duration = os.system(cmd)
print duration

Am I doing the output redirect wrong? Or is there simply no way to pipe the terminal output back into python?

© Stack Overflow or respective owner

Related posts about python

Related posts about redirect