2012-09-14 63 views
2

只是想知道是否有人能告訴我爲什麼命令VS子

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 

雙方應該找到的文件應該不是嗎?

回答

7

commands spaws一個殼,其確實的水珠擴張。 subprocess不生成一個shell,除非你通過shell = True

換句話說:

p=subprocess.Popen("ls *00080",shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 

應該做的commands做同樣的事情。