I'm trying to find a way to ignore the stderr stream (something similar to 2> /dev/null
):
output = subprocess.check_output("netstat -nptl".split())
What should I add to the above command to achieve this?
I'm trying to find a way to ignore the stderr stream (something similar to 2> /dev/null
):
output = subprocess.check_output("netstat -nptl".split())
What should I add to the above command to achieve this?
Just tell subprocess
to redirect it for you:
import subprocess
output = subprocess.check_output(
"netstat -nptl".split(), stderr=subprocess.DEVNULL
)
For python 2, it's a bit more verbose.
import os
import subprocess
with open(os.devnull, 'w') as devnull:
output = subprocess.check_output(
"netstat -nptl".split(), stderr=devnull
)