I have an application that logs a lot of noise to stderr and REALLY slows down the execution of the application. I would like to redirect that output to null. Is this possible with cmd.exe?
Asked
Active
Viewed 1.6e+01k times
158
-
24like this: command 2> nul – Naytzyrhc Dec 22 '10 at 08:22
-
2See also on superuser: [> /dev/null for Windows](http://superuser.com/questions/134214) – hippietrail Dec 20 '13 at 15:28
-
9I you want to totally silence a command (stdout and stderr) do `@command > nul 2>&1` – kofifus Nov 12 '19 at 22:56
1 Answers
221
Your DOS command 2> nul
Read page Using command redirection operators. Besides the "2>" construct mentioned by Tanuki Software, it lists some other useful combinations.
-
1However following will do almost the opposite of what some may expect `copy foo.txt con >> bar 2>nul`. bar will contain the text *one file(s) copied* and the console will containt the content of *foo.txt*. – Patrick Fromberg Jul 02 '14 at 08:31
-
Note that this method outputs a blank line, which might cause problems for some scripts. I am still trying to find a way to suppress that. – Mawg says reinstate Monica Mar 04 '16 at 11:05
-
1@Mawg I don't think it does. It's probably something specific to your usage scenario. Case in point: `@for /L %C in (1,1,10) do @type nonexistent 2> nul` does **not** produce ten blank lines. – atzz Mar 04 '16 at 12:10
-
2@PatrickFromberg That's because `con` is not a synonym for STDOUT; it's a pseudofile associated with actual console, so it's not affected by redirection. Somewhat akin to Linuxish `(cat /proc/version > /dev/tty) > bar`: the outer redirect won't affect the inner one. – atzz Mar 04 '16 at 12:17
-
If I give `non exitsant command` or soem random `umjumflunge` and redirect to `nul`, I still get a blank lien at the DOD prompt – Mawg says reinstate Monica Mar 04 '16 at 12:25
-
@Mawg That's just the interactive cmd behavior which won't affect scripting. It simply adds a blank line after each interactive command it executes, I/O redirection or not. Try: http://pastebin.com/JMeA6Mti – atzz Mar 04 '16 at 12:45
-
I think there is a problem in the accepted answer. It should be 2>&1> nul You are only redirecting stderr; not stdout, as in `gswin64c --help 2>&1> nul` – Sam Habiel Jul 15 '16 at 19:56
-
1
-
3Referenced page is here: https://technet.microsoft.com/en-us/library/bb490982.aspx – legalize Sep 29 '17 at 00:30
-
1DOS commands aren't supported any more are they? A win console command, yes. – Gringo Suave Oct 19 '18 at 23:55
-
1I always forget it's one `l` then end up creating a file called `null` and get unreasonably pissed off – solstice333 Mar 01 '23 at 18:33