在 Python 中执行 shell 命令的推荐库

我推荐使用 invoke 而不是内置的 subprocess 来处理在 Python 中执行任何 shell 命令。

不仅 invokerun() 提供了比例如 subprocess.check_output() 更友好的语法:

而且它往往更符合你的预期,特别是在命令输出方面,并具有易于使用的参数,如 hide=True 来隐藏 shell 命令的输出。

此外,它提供了一堆非常有用的功能,例如自动响应 shell 命令的提示。


Check out similar posts by category: Python