Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does > nul 2>&1 mean in a batch statment

Tags:

batch-file

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

like image 972
MistyD Avatar asked Jun 13 '15 00:06

MistyD


People also ask

What does 2 NUL mean?

stream 1 is the standard input/output stream, 2 is the standard error stream. A command can output to multiple streams and it's allowed to redirect each of them to a different destination. So 2>nul and 1>nul simply said that the error output and the normal output will be redirected to nul. So nothing will be outputted.

What does NUL mean in batch?

nul 2>nul. means ignore output of command and ignore error messages.

What does the NUL command do?

The null device is a special file that discards all data written to it, but reports that the write operation succeeded. Nul is often used to hide the output (or error output) of a command. It is called NUL rather than NULL for historical reasons, many other devices have 3 character names: AUX, PRN, CON, etc.

What is Type NUL?

Type: Null (Japanese: タイプ:ヌル Type: Null) is a Normal-type Legendary Pokémon introduced in Generation VII. It evolves into Silvally when leveled up with high friendship.


1 Answers

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.

like image 81
iAdjunct Avatar answered Sep 24 '22 07:09

iAdjunct