[Tutor] os.system vs subprocess.Popen args problems

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Sep 2 16:44:25 CEST 2013


On 2 September 2013 15:19, learner404 <learner404 at gmail.com> wrote:
> Hello,
>
> I can't understand why the command below works with os.system but not with
> subprocess.Popen (on windows, recording video with FFMPEG.exe)
>
> cmd=('ffmpeg -f dshow -i video="%s" -f dshow -i audio="%s" -q 5
> "%s"')%(videoinputName, audioinputName, videoFileOutput)
> os.system(cmd)
> *works*
>
> subprocess.Popen(["ffmpeg","-f","dshow","-i",'video="%s"'%videoinputName,"-f","dshow","-i",'audio="%s"'%audioinputName,"-q","5","%s"%videoFileOutput])

I think you need additional quotes for the videoFileOutput part e.g.

'"%s"' % videoFileOutput

> *don't work*
>>> [dshow @ 025984a0] Could not find video device.
>>> video="QuickCam Orbit/Sphere AF": Input/output error

I see that video has spaces in it. You'd think it was unnecessary to
have those quotes since you've already split the command string into a
list of strings. Unfortunately Windows has a fairly arcane way of
handling arguments to subprocesses and Python tries to emulate that:
http://docs.python.org/2/library/subprocess.html#converting-an-argument-sequence-to-a-string-on-windows

> The reason I'm going with subprocess is to avoid to have the DOS window
> coming in the forefront.
> Any idea of what I'm doing wrong? Or any other way to hide or minimize the
> DOS window?

Another thing is that you shouldn't use Popen directly unless you're
doing something fancy (which you're not if os.system does what you
want). Use subprocess.check_call instead:

subprocess.check_call(["ffmpeg","-f","dshow","-i",'video="%s"'%videoinputName,"-f","dshow","-i",'audio="%s"'%audioinputName,"-q","5",'"%s"'%videoFileOutput])


Oscar


More information about the Tutor mailing list