Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subprocess.run not suppressing all console output

subprocess.run with stdout=DEVNULL and stderr=STDOUT does not suppress all output from the subinacl.exe utility.

>>> # 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)
>>>

My guess is that subinacl.exe is calling another process that prints the output that is not being suppressed. Don't stdout=DEVNULL and stderr=STDOUT silence output from the whole process chain?

like image 277
R01k Avatar asked Sep 06 '25 02:09

R01k


1 Answers

Based on Eryk Sun comment, I had to use

subprocess.run(
    'subinacl.exe /service "foo" display',
    stdout=subprocess.DEVNULL,
    stderr=subprocess.STDOUT, 
    creationflags=subprocess.CREATE_NO_WINDOW
)
like image 60
R01k Avatar answered Sep 08 '25 00:09

R01k