如何防止 pyinvoke "UnexpectedExit: Encountered a bad command exit code!"
问题:
当你尝试使用 pyinvoke 的 invoke.run() 运行命令时,原生命令返回非零退出代码,使你的脚本失败而不是继续(例如评估输出):
pyinvoke_traceback.txt
Traceback (most recent call last):
File "/home/user/myscript.py", line 7, in <module>
result = invoke.run("mycommand", out_stream=outStream)
# ...
File "/usr/local/lib/python3.10/dist-packages/invoke/runners.py", line 518, in _finish
raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!解决方案
使用 warn=True 作为 invoke.run() 的参数
这将告诉 invoke 仅警告你命令以非零退出状态退出,而不是抛出 UnexpectedExit
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow