I usually use very simply subprocess.check_output
:
process = subprocess.check_output("ps aux", shell=True)
print process #display the list of process
If I fear there is something in stderr
, I use it like that:
process = subprocess.check_output("ps aux 2> /dev/null", shell=True)
print process #display the list of process
But I have a problem with nginx -V
:
modules = subprocess.check_output("nginx -V", shell=True) #display the result
print modules #empty
modules = subprocess.check_output("nginx -V 2> /dev/null", shell=True) #display nothing
print modules #empty
Why is the command nginx -V
behaving differently (all printing in stderr
)? How can I design esealy a workaround with ``subprocess.check_output`?