37

I currently have a batch statement that looks like this

findstr "PreprocessorDefinitions=.*%D_KEYWORD%" %PROJ% > nul 2>&1
if errorlevel 1 (
    set D_OPT=
) else (
    set D_OPT=/D%D_KEYWORD%
)

I wanted to know what the following means ?

> nul 2>&1

I looked here and it states that

... >nul 2>nul

means ignore output of command and ignore error messages

Now my question is how can I modify this command

 findstr "PreprocessorDefinitions=.*%D_KEYWORD%" %PROJ% > nul 2>&1

to show everything and not to ignore the error messages

Sercan
  • 4,739
  • 3
  • 17
  • 36
MistyD
  • 16,373
  • 40
  • 138
  • 240
  • 2
    Standard output is going to `nul` and standard error output (file descriptor 2) is being sent to standard output (file descriptor 1) so both error and normal output go to the same place. In Windows, `nul` is a null device, which means the output is just flushed and you don't see it. Thus, in this case, all output is being flushed. – lurker Jun 13 '15 at 00:35
  • Thanks for clearing that up – MistyD Jun 13 '15 at 00:35
  • If you want to see everything on your screen, just get rid of the `> nul 2>&1`. – lurker Jun 13 '15 at 00:35
  • Possible duplicate of [In the shell, what does " 2>&1 " mean?](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean) – wesinat0r Dec 08 '18 at 19:58

1 Answers1

62

Don't use a redirection operator, which is what ">" is.

All programs have three streams:

  • Standard Input (the input from the console)
  • Standard Output (general logging/UI output to the console)
  • Standard Error (logging/UI output to the console meant for error messages or other exceptional behavior)

command >nul

^ This says to pipe the standard-output stream to null.

command 2>nul

^ This says to pipe the standard-error stream to null.

command 2>&1

^ This says to pipe the standard-error stream to the same place as the standard-output stream.

Chris D
  • 102
  • 1
  • 7
iAdjunct
  • 2,739
  • 1
  • 18
  • 27