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?
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?
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.)