python Shell接口通过sh模块。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Shell接口通过sh模块。相关的知识,希望对你有一定的参考价值。

from sh import echo

#
print(echo("wlan0"))

# Passing Arguments
sh.ls("-l", "/tmp", color="never")

# Subcommands
sh.git("show", "HEAD")
sh.git.show("HEAD")  # equivalent

# Background Processes
p = sh.find("-name", "sh.py", _bg=True)
... do other things ...
p.wait()

#exit codes
try:
    sh.ls("/doesnt/exist")
except sh.ErrorReturnCode_2:
    print("directory doesn't exist")

以上是关于python Shell接口通过sh模块。的主要内容,如果未能解决你的问题,请参考以下文章

如何从 python 代码调用 shell 脚本?

如何在shell中执行一个模块,这个模块需要传入参数

通过 shell 调用 python 时出现模块问题

shell的可执行权限

shell输入显示带颜色字体的模块脚本

python 基础 7.5 commands 模块