繁体   English   中英

subprocess.run 不抑制所有控制台 output

[英]subprocess.run not suppressing all console output

带有stdout=DEVNULL subprocess.run stderr=STDOUT的 subprocess.run 不会抑制来自subinacl.exe实用程序的所有 output。

>>> # Do not suppress: OK
>>> subprocess.run('subinacl.exe /service "foo" display', shell=True)
foo - OpenService Error : 1060 The specified service does not exist as an installed service.



Elapsed Time: 00 00:00:00
Done:        1, Modified        0, Failed        1, Syntax errors        0
Last Done  : foo
Last Failed: foo - OpenService Error : 1060 The specified service does not exist as an installed service.

CompletedProcess(args='subinacl.exe /service "foo" display', returncode=0)

>>> # Suppress: Some output is still printed
>>> subprocess.run('subinacl.exe /service "foo" display', shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)

Elapsed Time: 00 00:00:00
Done:        1, Modified        0, Failed        1, Syntax errors        0
Last Done  : foo
Last Failed: foo - OpenService Error : 1060 The specified service does not exist as an installed service.

CompletedProcess(args='subinacl.exe /service "foo" display', returncode=0)
>>>

我的猜测是 subinacl.exe 正在调用另一个进程,该进程打印未被抑制的 output。 不要stdout=DEVNULLstderr=STDOUT使整个流程链中的 output 静音吗?

根据 Eryk Sun 的评论,我不得不使用

subprocess.run(
    'subinacl.exe /service "foo" display',
    stdout=subprocess.DEVNULL,
    stderr=subprocess.STDOUT, 
    creationflags=subprocess.CREATE_NO_WINDOW
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM