Pylint 和 Subprocess.Run 返回退出状态 28
Pylint and Subprocess.Run returning Exit Status 28
我正在尝试 运行 使用子进程的 pylint,但收到一条模糊的消息,说明非零退出状态 28。我找不到任何对 Pylint 或子进程的退出状态 28 的引用。
我只能假设这是一个 pylint/windows 问题,因为 运行 宁其他一些典型的命令,例如head,和直接在控制台中 运行ning pylint 一样工作得很好。
运行 python 3.5 在 Windows 10.
有什么想法吗?
MWE
import subprocess
cmd = 'pylint test_script.py'
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(subprocComplete.stdout.decode('utf-8'))
输出
python35 pylint_subprocess_test.py
Traceback (most recent call last):
File "pylint_subprocess_test.py", line 3, in <module>
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Python35\lib\subprocess.py", line 708, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'pylint test_script.py' returned non-zero exit status 28
如果子进程 returns 非零(pylint 通常会这样),那么 subprocComplete
永远不会被分配。您可以捕获错误,错误对象保存您想要的输出。
import subprocess
cmd = 'pylint test_script.py'
try:
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(subprocComplete.stdout.decode('utf-8'))
except subprocess.CalledProcessError as err:
print(err.output.decode('utf-8'))
我正在尝试 运行 使用子进程的 pylint,但收到一条模糊的消息,说明非零退出状态 28。我找不到任何对 Pylint 或子进程的退出状态 28 的引用。
我只能假设这是一个 pylint/windows 问题,因为 运行 宁其他一些典型的命令,例如head,和直接在控制台中 运行ning pylint 一样工作得很好。
运行 python 3.5 在 Windows 10.
有什么想法吗?
MWE
import subprocess
cmd = 'pylint test_script.py'
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(subprocComplete.stdout.decode('utf-8'))
输出
python35 pylint_subprocess_test.py
Traceback (most recent call last):
File "pylint_subprocess_test.py", line 3, in <module>
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
File "C:\Python35\lib\subprocess.py", line 708, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'pylint test_script.py' returned non-zero exit status 28
如果子进程 returns 非零(pylint 通常会这样),那么 subprocComplete
永远不会被分配。您可以捕获错误,错误对象保存您想要的输出。
import subprocess
cmd = 'pylint test_script.py'
try:
subprocComplete = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(subprocComplete.stdout.decode('utf-8'))
except subprocess.CalledProcessError as err:
print(err.output.decode('utf-8'))