I want to make it so that the “stdout” and “stderr” output from “check_call()” is sent to Syslog. Is this possible?
Code:
def command(cmd, err=None, ifexit=False):
try:
check_call(shlex.split(cmd), stdout=null, stderr=null)
except CalledProcessError:
if err != None:
print err
if ifexit == True:
exit(1)
Yes it is possible, but i think you would need to use
Popeninstead ofcheck_call, and send the process’stdoutandstderrto a properly configured logger.Such a logger would use
logging.handlers.SysLogHandlerto send messages to your syslog server. Here is a short example of how such a logger could be created:And here is an example of how you could replace
check_callwithPopenand send the data to the logger: