158

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207

1 Answers1

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.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
atzz
  • 17,507
  • 3
  • 35
  • 35
  • 1
    However 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
    @SamHabiel Not really. The question is about `stderr`. – atzz Jul 18 '16 at 08:36
  • 3
    Referenced page is here: https://technet.microsoft.com/en-us/library/bb490982.aspx – legalize Sep 29 '17 at 00:30
  • 1
    DOS commands aren't supported any more are they? A win console command, yes. – Gringo Suave Oct 19 '18 at 23:55
  • 1
    I 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