How do you stop the output from subprocess.Popen from being output? Printing can sometimes be slow if there is a great deal of it.
To hide output of subprocess with Python, we can set stdout to subprocess. DEVNULL`. to output the echo command's output to dev null by setting the stdout to subprocess. DEVNULL when we call subprocess.
To capture the output of the subprocess. run method, use an additional argument named “capture_output=True”. You can individually access stdout and stderr values by using “output. stdout” and “output.
The subprocess module defines one class, Popen and a few wrapper functions that use that class. The constructor for Popen takes arguments to set up the new process so the parent can communicate with it via pipes. It provides all of the functionality of the other modules and functions it replaces, and more.
If you want to totally throw it away:
import subprocess import os with open(os.devnull, 'w') as fp: cmd = subprocess.Popen(("[command]",), stdout=fp)
If you are using Python 2.5, you will need from __future__ import with_statement
, or just don't use with
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With