我使用 subprocess 模块在 python 3 中运行 shell 命令。
这是我的代码
import subprocess
filename = "somename.py" # in practical i'm using a real file, this is just for example
subprocess.call("pep8 %s" % filename, shell=True))
不同文件的输出只是0
or 1
。我对 python 3 很陌生。在 2.7 中使用它给了我所需的输出,但在这里我无法弄清楚。
这是我在 python 2.7 中得到的输出(对于名为 - 的文件)anu.py
) -
anu.py:2:1: W191 indentation contains tabs
anu.py:3:1: W191 indentation contains tabs
anu.py:3:7: E228 missing whitespace around modulo operator
anu.py:4:1: W191 indentation contains tabs
anu.py:5:1: W191 indentation contains tabs
anu.py:6:1: W191 indentation contains tabs
anu.py:7:1: W191 indentation contains tabs
anu.py:7:9: E231 missing whitespace after ','
anu.py:8:1: W191 indentation contains tabs
anu.py:9:1: W191 indentation contains tabs
1
请帮助我。
谢谢
Update:
我尝试使用subprocess.check_output
method,
这是我得到的输出,
>>> subprocess.check_output(["pep8", "anu.py"])
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "X/subprocess.py", line 584, in check_output
it too will be used internally. Example:
subprocess.CalledProcessError: Command '['pep8', 'anu.py']' returned non-zero exit status 1