|
Syntax : Redirection
command > filename Redirect command output into a file command >> filename Redirect command output and APPEND into a file command < filename Redirect a file into a command command | command Pipe the output from one command into another command command & command Perform the first command & then perform the second command. command 2> filename Redirect any error message into a file command 2> nul Redirect any error message to NUL command > filename 2> filename Redirect output and errors to separate files command > filename 2>&1 Redirect output and errors to one file
Note, any long filenames must be surrounded in "double
quotes".
Redirection with > or 2> will overwrite any
existing file.
You can also redirect to a printer with > PRN or >LPT1
To prevent '>' from causing redirection use an escape character '^>'
some examples of redirection:
DIR >MyFileListing.txt DIR /o:n >"Another list of Files.txt" MEM /C >>MemoryUseLog.txt Date /T >>MemoryUseLog.txt SORT < MyTextFile.txt SET v_output=%v_missing% 2>nul DIR C:\ >List_of_C.txt 2>errorlog.txt FIND /i "Jones" < names.txt >logfile.txt DIR C:\ >List_of_C.txt & DIR D:\ >List_of_D.txt ECHO DIR C:\ ^> c:\logfile.txt >NewScript.cmd
Related:
NT Syntax
Q245031 - Error when
using the | pipe symbol
Linux BASH equivalent commands:
Redirection - Spooling output to
a file, piping input