Redirection
| Commands | Description |
|---|---|
| command > file | Write standard output of command to file |
| command 1> file | Write standard output of command to file (same as previous) |
| command 2> file | Write standard error of command to file (OS/2 and NT) |
| command > file 2>&1 | Write both standard output and standard error of command to file (OS/2 and NT) |
| command >> file | Append standard output of command to file |
| command 1>> file | Append standard output of command to file (same as previous) |
| command 2>> file | Append standard error of command to file (OS/2 and NT) |
| command >> file 2>&1 | Append both standard output and standard error of command to file (OS/2 and NT) |
| commandA | commandB | Redirect standard output of commandA to standard input of commandB |
| commandA 2>&1 | commandB | Redirect standard output and standard error of commandA to standard input of commandB (OS/2 and NT) |
| command < file | command gets standard input from file |
| command 2>&1 | command’s standard error is redirected to standard output (OS/2 and NT) |
| command 1>&2 | command’s standard output is redirected to standard error (OS/2 and NT) |
Notes:
(1) Where the table mentions redirection to a file you may also use redirection to a device. Redirection from a device is not always possible.
(2) Redirection to the NUL device is often used to hide standard output, instead of displaying it on screen:
COPY *.* A: > NUL
Another frequently used redirection is redirection to a parallel port to print standard output:
DIR > LPT1
For details, please go to http://www.robvanderwoude.com/redirection.php

本文详细介绍了命令行中各种重定向操作的使用方法,包括标准输出、标准错误的重定向到文件、设备,以及从文件读取输入等。此外还列举了一些常用的重定向示例,如将输出隐藏或发送到打印机。
1480

被折叠的 条评论
为什么被折叠?



