4

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?

Community
  • 1
  • 1
Boaz
  • 4,864
  • 12
  • 50
  • 90

1 Answers1

11

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()
Community
  • 1
  • 1
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306