subprocess.run
并且不会抑制subinacl.exe实用程序stdout=DEVNULL
的所有输出。stderr=STDOUT
>>> # 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 正在调用另一个进程来打印未被抑制的输出。不要让整个流程链的输出保持沉默stdout=DEVNULL
?stderr=STDOUT