Uncategorized

Python 使用 subprocess 调用外部命令行程序报错 – V2EX



先把 stderr 重定向到 stdout 里,看一下是程序内部报错,还是环境问题,
参考:
https://stackoverflow.com/questions/16198546/get-exit-code-and-stderr-from-subprocess-call

shell=True 可能不需要,根据你原先代码来改

“`
try:
output = subprocess.check_output(
cmnd, stderr=subprocess.STDOUT, shell=True, timeout=3,
universal_newlines=True)
except subprocess.CalledProcessError as exc:
print(“Status : FAIL”, exc.returncode, exc.output)
else:
print(“Output: \n{}\n”.format(output))
“`



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *