Redirect all output to /dev/null on Windows Command

A lot of Linux code redirects output to /dev/null as a way of not sending any output to the console. I work in Windows and often use Command Prompt (cmd.exe) as the command shell. This is just a small note to remember how to do the same in Windows.

Not much here – it’s just:

$ your_command > NUL 2>&1

The > NUL redirects the stdout to the NUL device (the equivalent of /dev/null) and the 2 >&1 also redirects the stderr to stdout so that nothing is output to the console.

I wrote this up so that I remembered what I had done (and why) – if this helps you, that’s great! If you have any comments or caught an error that slipped by, please let me know in the comments below.

comments powered by Disqus