所以我想使用args从python执行cmd命令并获取输出。示例:
console.py "dir c: >> C:\test\cmdoutput.txt"
这是我的python(2.7)代码:
import sys
import subprocess
subprocess.run(str(sys.argv))
输出:
Traceback (most recent call last):
File "C:\Users\Solo\PycharmProjects\Hacking\Console.py", line 6, in <module>
subprocess.run(str(sys.argv))
AttributeError: 'module' object has no attribute 'run'
答案 0 :(得分:0)
.run
仅根据the docs在Python 3.5中添加:
run()函数是在Python 3.5中添加的;如果您需要保持与旧版本的兼容性,请参见Older high-level API section。
您可能应该使用call
,check_output
或check_call
之一