I'd like to operate a process using supervisorctl
from python code, in order to get the status and make conditional branches like this:
import subprocess
status = subprocess.run(["sudo", "supervisorctl", "status", "my_process"])
if status == "STOPPED":
# Do something
else:
# Do another thing
But this doesn't work. subprocess.run
returns CompletedProcess(args=['sudo', 'supervisorctl', 'status', 'my_status'], returncode=0)
. The response doesn't have what the status is.
Is there any way to get the status?
I think you need to use subprocess.check_output()
to get the output returned to you rather than just the return code.
subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
Run command with arguments and return its output as a byte string.