CMD 2 - ;&放大器1为卤素;登录VS CMD>日志2 - ;&放大器; 1 [英] cmd 2>&1 > log vs cmd > log 2>&1

查看:129
本文介绍了CMD 2 - ;&放大器1为卤素;登录VS CMD>日志2 - ;&放大器; 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之间有什么区别:

cmd > log 2>&1

cmd 2>&1 > log

其中cmd是命令?

where cmd is a command?

这应该我preFER为什么?

Which should I prefer and why?

推荐答案

订单事宜。来思考重定向的方式是从左至右阅读并意识到重定向使流点在同一个地方。他们不互相使流点。

Order matters. The way to reason about redirections is to read them from left to right and realize that redirections make streams point at the same place. They don't make streams point at each other.

这是什么意思?如果你说 2 - ;&放大器; 1 然后要重定向错误输出到标准输出的地方,目前重定向到。如果stdout是要控制台,然后标准错误,太。如果stdout是去一个文件,那么标准错误也是如此。如果按照这个增长然后重定向标准输出,标准错误仍然指向什么标准输出的使用以指向。它并不跟随标准输出到新的位置。

What does that mean? If you say 2>&1 then you are redirecting stderr to wherever stdout is currently redirected to. If stdout is going to the console then stderr is, too. If stdout is going to a file then stderr is as well. If you follow this up by then redirecting stdout, stderr still points to what stdout used to point to. It does not "follow" stdout to the new location.

cmd > log 2>&1

此标准输出重定向到登录,然后重定向标准错误到哪里标准输出已经被重定向,这是登录

This redirects stdout to log and then redirects stderr to wherever stdout is now being redirected, which is log.

最终结果: stdout和标准错误将被重定向到登录

End result: both stdout and stderr are redirected to log.

cmd 2>&1 > log

此标准错误重定向到任何地方标准输出当前正在重定向,这通常是控制台。然后,标准输出重定向到日志。请记住,stderr并不跟随标准输出,所以它继续重定向到控制台。

This redirects stderr to wherever stdout is currently being redirected, which is typically the console. Then stdout is redirected to log. Remember that stderr does not "follow" stdout, so it continues to redirect to the console.

最终结果:标准输出重定向到日志文件和标准错误(仍然)发送到控制台。这当然不是你想要的。

End result: stdout is redirected to the log file and stderr is (still) sent to the console. This is almost certainly not what you want.

这篇关于CMD 2 - ;&放大器1为卤素;登录VS CMD>日志2 - ;&放大器; 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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