Boaz
Boaz

Reputation: 5084

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?

Upvotes: 4

Views: 4028

Answers (1)

Andrew Clark
Andrew Clark

Reputation: 208475

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

Upvotes: 11

Related Questions