只是想知道是否有人能告诉我原因
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
给出输出:
o ls: cannot access *00080: No such file or directory
o 010.010.013.165.42974-010.010.013.164.00080
两者都应该找不到文件吗?
A
答案 0 :(得分:10)
commands
会产生一个执行glob扩展的shell。除非您通过subprocess
,否则shell = True
不会生成shell。
换句话说:
p=subprocess.Popen("ls *00080",shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
应该做commands
做的事情。