Just wondering if anybody could tell me why
import subprocess, commands
p=subprocess.Popen(["ls", "*00080"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output=p.communicate()[0]
print "o", output
result=commands.getoutput("ls *00080")
print "o", result
gives the outputs:
o ls: cannot access *00080: No such file or directory
o 010.010.013.165.42974-010.010.013.164.00080
Both should find the file shouldn't they?
A
commands
spaws a shell which does the glob expansion. subprocess
doesn't spawn a shell unless you pass shell = True
.
In other words:
p=subprocess.Popen("ls *00080",shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
should do the same thing that commands
did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With