How can I silence ALL output from a command in a batch file?

I figured that 2>NUL at the end of DOS commands was enough, but it seems some messages, some error, still get through. So how can I cut off all output whatsoever? Or should I just forget it and allow output through?

2 Answers

Start your batch file with:

@ECHO OFF

And redirect all command output by appending:

>NUL 2>&1

This redirects "Standard Out" (1) to NUL and redirects "Standard Error" (2) to (1).

1

The 2>NUL redirection suppresses error output, but has no effect on standard output messages.

The usual way to redirect both is >NUL 2>&1, and you should use this form when redirecting both to a file. However, for the NUL device, you could also use the marginally less efficient >NUL 2>NUL.

See this link for a full description of redirection options.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like