import os
result = os.popen("start /wait cmd /c dir/s *.exe > Allexe1.txt").read()
if result is not None:
#this is your object with all your results
#you can write to a file
with open('output.txt', 'w') as f:
f.write(result)
#you can also print the result to console.
print result
else:
print "Command returned nothing"
试试这个
您应该能够按照自己的方式进行此更改,因为
start /wait cmd /c
不需要通过os.system
执行命令:然而,如果你打算把它移到非windows平台上,这就不是可移植的代码。在
如果你想用更便携的方式来做,我建议你读这篇question/answer
^{pr2}$您不应该以这种方式枚举Python中的文件。相反,请使用包含的
glob
模块:或者,因为您似乎想要所有的子目录,请将}结合使用,如
os.walk()
与{glob
文档中所述。无论如何,你不应该为此付出代价。在https://docs.python.org/2/library/glob.html
相关问题 更多 >
编程相关推荐