If you're using Python 3.3+, you can use the DEVNULL
special value for stdout
and stderr
to discard subprocess output.
from subprocess import Popen, DEVNULL
process = Popen(["mycmd", "myarg"], stdout=DEVNULL, stderr=DEVNULL)
Or if you're using Python 2.4+, you can simulate this with:
import os
from subprocess import Popen
DEVNULL = open(os.devnull, 'wb')
process = Popen(["mycmd", "myarg"], stdout=DEVNULL, stderr=DEVNULL)
However this doesn't give you the opportunity to read the first byte of stdout.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…