Answer the question
In order to leave comments, you need to log in
How to handle error output in a Python script on Debian?
There is a Python script that runs mosquitto via subprocess.
The program runs, but writes to Syslog:
Warning: Unable to locate configuration directory, default config not loaded.
This error is not critical and can only be removed by updating the mosquitto version, which is not possible.
Question - how can I make sure that this particular error is not written to the log, and the rest are written?
How do I run mosquitto:
try:
subprocess.check_call(args)
except subprocess.CalledProcessError as e:
sys.stderr.write(
'ERROR: call to mosquitto_pub failed with error code {}\n'.format(e.returncode))
Answer the question
In order to leave comments, you need to log in
For example like this:
ERR = 'Warning: Unable to locate configuration directory, default config not loaded.'
try:
output = subprocess.check_output(args)
except subprocess.CalledProcessError as e:
sys.stderr.write(
'ERROR: call to mosquitto_pub failed with error code {}\n'.format(e.returncode))
else:
for line in output.decode('utf-8').split('\n'):
if err not in line:
print(line, file=sys.stderr)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question