What is "2>" for in DOS / Windows console? (cmd.exe)

I've seen the following line in a .cmd file:

ren fileA fileB 2> nul

I know what ">nul" is for (to prevent any output from appearing), but what is "2> nul" for?

1 Answer

There are actually two console output streams – stdout (1) and stderr (2). The former is supposed to be used for regular data output, while stderr is meant for warnings and error messages.

By default the > operator redirects only stdout; prefixing it with 2 will cause it redirect stderr instead. This lets you avoid accidentally mixing program warnings into data files.

(On Unix-like systems all redirection operators accept any fd number. Windows only borrowed the syntax but has a different underlying system, so it only deals with in/out/err.)

3

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