How to redirect stderr to null in cmd.exe [closed]
Asked Answered
A

1

163

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?

Adrenalin answered 22/12, 2010 at 8:14 Comment(4)
like this: command 2> nulIdzik
See also on superuser: > /dev/null for WindowsAutocephalous
I you want to totally silence a command (stdout and stderr) do @command > nul 2>&1Mandrake
Super User would be a better place to ask questions about how to use your computer.Cleres
D
225
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.

Dorolice answered 22/12, 2010 at 9:6 Comment(11)
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.Unweave
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.Sidnee
@Sidnee 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.Dorolice
@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.Dorolice
If I give non exitsant command or soem random umjumflunge and redirect to nul, I still get a blank lien at the DOD promptSidnee
@Sidnee 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: pastebin.com/JMeA6MtiDorolice
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> nulEdgeworth
@SamHabiel Not really. The question is about stderr.Dorolice
Referenced page is here: technet.microsoft.com/en-us/library/bb490982.aspxErmelindaermengarde
DOS commands aren't supported any more are they? A win console command, yes.Kunin
I always forget it's one l then end up creating a file called null and get unreasonably pissed offSway

© 2022 - 2024 — McMap. All rights reserved.