更新时间:2022-06-22 08:40:42
Out-Null
在非PowerShell命令中也可以正常工作.但是,它不抑制STDERR
上的输出,仅抑制STDOUT
上的输出.如果还要抑制在STDERR
上的输出,则必须在将输出传递到Out-Null
之前将文件描述符重定向到STDOUT
:
Out-Null
works just fine with non-PowerShell commands. However, it doesn't suppress output on STDERR
, only on STDOUT
. If you want to suppress output on STDERR
as well you have to redirect that file descriptor to STDOUT
before piping the output into Out-Null
:
hg st 2>&1 | Out-Null
2>
重定向STDERR
(文件描述符#2)的所有输出. &1
将重定向的输出与STDOUT
的输出(文件描述符#1)合并.然后将合并的输出打印到STDOUT
,管道可以在此处将其输出到管道中下一个命令的STDIN
中(在本例中为Out-Null
).有关更多信息,请参见 Get-Help about_Redirection
.
2>
redirects all output from STDERR
(file descriptor #2). &1
merges the redirected output with the output from STDOUT
(file descriptor #1). The combined output is then printed to STDOUT
from where the pipe can feed it into STDIN
of the next command in the pipline (in this case Out-Null
). See Get-Help about_Redirection
for further information.