For python >= 3.3, Redirect the output to DEVNULL:
import os
import subprocess
retcode = subprocess.call(['echo', 'foo'],
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
For python <3.3, including 2.7 use:
FNULL = open(os.devnull, 'w')
retcode = subprocess.call(['echo', 'foo'],
stdout=FNULL,
stderr=subprocess.STDOUT)
It is effectively the same as running this shell command:
retcode = os.system("echo 'foo' &> /dev/null")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…