Redirect operators

Category: Command prompt / Cygwin Shell
------------------------------------------------------------


Often during execution of make or batch file the output generates error, and more so ever these errors cross limit of scroll limits of shell!
The simplest solution developers use to redirect output...and it adds more frustration as simple redirect operator > or "| tee" does not log errors! And "| more" is not supported by Windows command prompt.

So, here is a list of some redirect operators which can log standard as well as error outputs.

Redirect operators:

1. ">" : Standard redirect operator
Usage: executable_name > output_file
Working : Standard output from executable is stored in output_file.

2. ">>" : Standard redirect operator with append option
Usage: executable_name >> output_file
Working : Standard output from executable is appended to output_file if it exits, else a new file is created.

3. "2>" : Errors / Warnings redirect operator
Usage: executable_name 2> error_file
Working : Error output from executable is stored in error_file.

4. "2>>" : Errors / Warnings redirect operator with append option
Usage: executable_name 2>> error_file
Working : Error output from executable is appended to error_file if file exists, else a new file is created.

An obvious question would arise is how do we redirect both standard and error outputs to a single file?
The answer is using by reference i.e "> output_file 2>&1"
Example:
executable_name > output_file 2>&1

Comments