Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide stdout of subprocess on windows

I know linux solutions of opening a /dev/null and redirecting stout to it.
(like Prevent subprocess of subprocess from writing to stdout or similar ones)
What is the solution in windows?

like image 285
Boaz Avatar asked Nov 02 '25 10:11

Boaz


1 Answers

Use the same approach, but use os.devnull which is the portable solution. On Windows this will send the output to NUL.

In fact, this solution is already recommended in the question you linked to:

with open(os.devnull, 'w') as tempf:
    proc = Popen(cmd, stdout=tempf, stderr=tempf)
    proc.communicate()
like image 61
Andrew Clark Avatar answered Nov 04 '25 00:11

Andrew Clark