"2& 1"是什么意思?在Windows命令中执行? [英] What does "2>&1" in a Windows Command Do?

查看:163
本文介绍了"2& 1"是什么意思?在Windows命令中执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在脚本上做一些维护,我发现了这一行:

Doing some maintenance on a script, I found this line:

ping -n 40 127.0.0.1 > NUL 2>&1

我从这个问题中知道 直到NUL为止的所有内容都会导致脚本休眠39秒.但是我不知道其余命令的作用.

I know from this question that everything up to the NUL causes the script to sleep for 39 seconds. But I don't know what the rest of the command does.

2>&1的作用是什么?

推荐答案

分解行

ping -n 40 127.0.0.1

向本地主机发送40个ping数据包.如果没有问题,则默认行为是在数据包之间等待1秒,因此会产生39秒的延迟

Send 40 ping packets to local host. If there is not any problem the default behaviour is to wait 1 second between packets, so it generates a 39 second delay

>nul   or   1>nul

将写入标准输出流(流编号1)的所有内容重定向到nul设备.发送到该设备的所有信息都将被丢弃.效果是ping命令的所有常规输出都被隐藏了.

Redirects anything written to the standard output stream (stream number 1) to the nul device. Anything sent to this device is discarded. The effect is that all the normal output of the ping command is hidden.

2>&1

这将重定向任何写入标准错误流(流编号2)的内容.与前面的情况一样,这样做是为了隐藏输出(在这种情况下为错误),但是此语法请求直接在nul设备中写数据(我们可能已经完成了2>nul),而不是直接请求写入nul设备(我们可能已经做过2>nul).标准错误流到标准输出流中使用的句柄的副本.

This redirects anything written to the standard error stream (stream number 2). As in the previous case, this is done to hide output (errors in this case), but instead of directly requesting to write to the nul device (we could have done 2>nul), this syntax requests to send data in the standard error stream to a copy of the handle used in the standard output stream.

这篇关于"2& 1"是什么意思?在Windows命令中执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆