Is there a quiet version of subprocess.call?

后端 未结 4 1651
渐次进展
渐次进展 2020-12-10 10:27

Is there a variant of subprocess.call that can run the command without printing to standard out, or a way to block out it\'s standard out messages?

4条回答
  •  情书的邮戳
    2020-12-10 10:52

    I use subprocess.check_output in such cases and drop the return value. You might want to add a comment your code stating why you are using check_output in place of check_call. check_output is also nicer when a failure occurs and you are interested in the error output. Example code below. The output is seen only when you uncomment the print line. If the command fails, an exception is thrown.

    import subprocess
    ret = subprocess.check_output(["cat", "/tmp/1"])
    #print ret
    

提交回复
热议问题