[我正在尝试找到一种在python脚本中运行秃鹰(在python项目中找到未使用的代码)的方法。秃documentation文档可以在这里找到:https://pypi.org/project/vulture/
有人知道怎么做吗?
我知道使用秃鹰的唯一方法是通过shell命令。我试图使用模块子进程从脚本调整shell命令,如下所示:
process = subprocess.run(['vulture', '.'], check=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)
尽管我将与运行shell命令“ vulture”具有相同的效果。
但是它不起作用。
有人可以帮忙吗?谢谢
我看到您想捕获控制台上显示的输出:
下面的代码可能会帮助:
import tempfile
import subprocess
def run_command(args):
with tempfile.TemporaryFile() as t:
try:
out = subprocess.check_output(args,shell=True, stderr=t)
t.seek(0)
console_output = '--- Provided Command: --- ' + '\n' + args + '\n' + t.read() + out + '\n'
return_code = 0
except subprocess.CalledProcessError as e:
t.seek(0)
console_output = '--- Provided Command: --- ' + '\n' + args + '\n' + t.read() + e.output + '\n'
return_code = e.returncode
return return_code, console_output
您的预期输出将显示在console_output
中
Link: