spock
6/11/2017 - 10:51 AM

Shell interface via sh module.

Shell interface via sh module.

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")