2011-08-16 5 views

답변

20

당신이 완전히 그것을 멀리 던져하려면 : 파이썬 2.5을 사용하는 경우

import subprocess 
import os 
with open(os.devnull, 'w') as fp: 
    cmd = subprocess.Popen(("[command]",), stdout=fp) 

, 당신은 from __future__ import with_statement이 필요합니다, 아니면 그냥 with를 사용하지 마십시오.

10

파이썬에서는 출력을 억제하기 위해, subprocess.DEVNULL 사용할 수 있습니다 3.3 이상 :

from subprocess import DEVNULL, STDOUT, check_call 

check_call([cmd, arg1, arg2], stdout=DEVNULL, stderr=STDOUT) 

stderr=STDOUT을 제거 당신은 또한 stderr을 억제하지 않으려면.

관련 문제