Suppress output from subprocess.Popen

后端 未结 2 488
情话喂你
情话喂你 2020-12-06 00:06

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.

2条回答
  •  离开以前
    2020-12-06 00:41

    In Python 3.3+ you could use subprocess.DEVNULL, to suppress the output:

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

    Remove stderr=STDOUT if you don't want to suppress stderr also.

提交回复
热议问题