Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Run A External Command From Python

DZone's Guide to

Run A External Command From Python

·
Free Resource
with new subprocess module (py2.4)

from subprocess import Popen,PIPE

p = Popen(file, shell=True,stdout=PIPE,stderr=PIPE)
out = string.join(p.stdout.readlines() )
outerr = string.join(p.stderr.readlines() )


with old way :

import os
out= string.join(os.popen(file).readlines())


or

os.spawnvp(os.P_WAIT,"/usr/bin/mplayer",["","-ao","pcm",file])

# or 

os.spawnvp(os.P_NOWAIT,"/usr/bin/mplayer",["","-ao","pcm",file])

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}