There are always three default files open, stdin (the keyboard), stdout (the screen), and stderr (error messages output to the screen). Redirection simply means capturing output from a file, command, program, script, or even code block within a script and and sending it as input to another file, command, program, or script.
Numeric handles for file descriptors:
STDIN = 0 Keyboard input
STDOUT = 1 Text output
STDERR = 2 Error text output UNDEFINED = 3-9
Numeric handles for file descriptors:
STDIN = 0 Keyboard input
STDOUT = 1 Text output
STDERR = 2 Error text output UNDEFINED = 3-9
REDIRECTION
command > filename Redirect command output to a file
command >> filename APPEND into a file
command < filename Pass a command from a text file
command A | command B Pipe the output from command A into command B
command A & command B Run command A and then run command B
command A && command B Run command A, if it succeeds then run command B
command A || command B Run command A, if it fails then run command B
command 2 > filename Redirect any error message into a file command 2 >> filename Append any error message into a file command > file 2>&1 Redirect errors and output to one file command > file 2<&1 Redirect output and errors to one file command > fileA 2> fileB Redirect output and errors to separate files command 2>&1 >filename -------------->Wrong command Redirect to NULL (hide errors) command 2> /dev/null Redirect error messages to NUL command >/dev/null 2>&1 Redirect error and output to NUL command >filename 2> /dev/null Redirect output to file but suppress error
We can also redirect to a printer with > PRN or >LPT1
For more info read here and to read commands of linux shell and vbscript read here
No comments:
Post a Comment