是否有 subprocess.call 的安静版本?

2022-01-18 00:00:00 python subprocess silent

问题描述

是否有 subprocess.call 的变体可以在不打印到标准输出的情况下运行命令,或者有一种方法可以阻止它的标准输出消息?

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?


解决方案

是的.将其 stdout 重定向到 /dev/null.

Yes. Redirect its stdout to /dev/null.

process = subprocess.call(["my", "command"], stdout=open(os.devnull, 'wb'))

相关文章