Sometimes, we want to hide output of subprocess with Python.
In this article, we’ll look at how to hide output of subprocess with Python.
How to hide output of subprocess with Python?
To hide output of subprocess with Python, we can set stdout
to subprocess.DEVNULL`.
For instance, we write
import os
import subprocess
c = subprocess.call(['echo', 'foo'],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
to output the echo command’s output to dev null by setting the stdout
to subprocess.DEVNULL
when we call subprocess.call
.
Conclusion
To hide output of subprocess with Python, we can set stdout
to subprocess.DEVNULL`.