sh - executing system commands and applications in Python
Check out the new site at https://rkblog.dev.
26 December 2012
Comments
sh is a wrapper around Python subprocess library. It offers a nice and easy to use API - it allows using programs or system commands like if they were a function.
The installation is typical: pip install sh. After installation you can import any system command or application from the sh module:
from sh import cd, ls, wesnoth
cd('/var/log')
print ls('./')
print wesnoth('--version')
from sh import cd, ls
cd('/var/log')
print ls.nginx('./')
from sh import git
git.checkout("master")
If you want to execute a command in background then use _bg=True. Data passed to standard output or error can be redirected to a file or function passed by using _out and _err arguments. You can also controll interactive commands.
RkBlog
Check out the new site at https://rkblog.dev.
Comment article