I'm using
(6:0)$ python --version
Python 2.7.1
One of the examples above is:
import subprocess
proc = subprocess.Popen(["cat", "/tmp/baz"], stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
print "program output:", out
For me, this failed to access the directory /tmp. After looking at the doc string for subprocess I replaced
[ "prog", "arg"]
with
"prog arg"
and got the shell expansion behavior that was desired (a la Perl's `prog arg`)
print subprocess.Popen("ls -ld /tmp/v*", stdout=subprocess.PIPE, shell=True).communicate()[0]
I quit using python a while back because I was annoyed with the difficulty of of doing the equivalent of perl `cmd ...`. I'm glad to find Python has made this reasonable.