I'm working on services with Python, when I try to get status of a service with Python sh library, It will return results in a variable like so:
import sh
status = str(sh.service('nginx','status'))
if 'active' in status:
print('ready')
It works fine, but when I try to get status of supervisor service it will print all the results in the terminal and destroys my command outputs.
So how to turn off this result which prints in terminal?
You'd need to redirect the output.
Either to /dev/null:
or to a
StringIOobject for you to check the output:Use
_errto redirect stderr output.