How to use the popen Python subprocess

Since os.popen is being replaced with subprocess.popen, I was wondering how I would convert

os.popen('swfdump /tmp/filename.swf/ -d') 

to subprocess.popen ()

I tried:

 subprocess.Popen("swfdump /tmp/filename.swf -d") subprocess.Popen("swfdump %s -d" % (filename)) # NOTE: filename is a variable # containing /tmp/filename.swf 

But I assume that I did not write it down correctly. Any help would be greatly appreciated. Thanks

+81
python subprocess popen
Sep 26 '12 at 15:42
source share
2 answers

subprocess.Popen accepts a list of arguments:

 from subprocess import Popen, PIPE process = Popen(['swfdump', '/tmp/filename.swf', '-d'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() 

There's even a documentation section on helping users migrate from os.popen to subprocess .

+114
Sep 26 '12 at 15:44
source share

Use sh , this will simplify:

 import sh print sh.swfdump("/tmp/filename.swf", "-d") 
+9
Sep 27 '12 at 4:14
source share



All Articles