在 Windows 中,2<&1 和 2>&1 之间有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8913119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:07:18  来源:igfitidea点击:

In Windows, what's the difference between 2<&1 and 2>&1?

windowsbatch-filecmd

提问by theglauber

The examples and explanations in this page are leaving me confused:

此页面中的示例和解释让我感到困惑:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx?mfr=true

Is there any practical difference between using 2<&1 and 2>&1? The second form (2>&1) is familiar to me, from working with the Unix shell.

使用 2<&1 和 2>&1 之间有什么实际区别吗?第二种形式 (2>&1) 对我来说很熟悉,因为它是在 Unix shell 中工作的。

The page linked above has:

上面链接的页面有:

To find File.txt, and then redirect handle 1 (that is, STDOUT) and handle 2 (that is, STDERR) to the Search.txt, type:
findfile file.txt>search.txt 2<&1

要查找 File.txt,然后将句柄 1(即 STDOUT)和句柄 2(即 STDERR)重定向到 Search.txt,请键入:
findfile file.txt>search.txt 2<&1

and also

并且

To redirect all of the output, including handle 2 (that is, STDERR), from the ipconfig command to handle 1 (that is, STDOUT), and then redirect the ouput to Output.log, type:
ipconfig.exe>>output.log 2>&1

要将所有输出(包括句柄 2(即 STDERR))从 ipconfig 命令重定向到句柄 1(即 STDOUT),然后将输出重定向到 Output.log,请键入:
ipconfig.exe>>output。日志 2>&1

In the end, is there any difference in the results?

最后,结果有什么不同吗?

采纳答案by Andy Morris

Some examples should show what happens:

一些示例应该显示会发生什么:

c:\YourDir> cd FolderNotHere > nul
The system cannot find the path specified. 

You get the error stream

你得到错误流

c:\YourDir>cd FolderNotHere > nul  2>&1

You get nothing, the error stream goes to the std output stream which goes to null.

你什么也得不到,错误流进入到空的 std 输出流。

c:\YourDir>cd > nul

You get nothing, the output stream goes to null.

你什么也得不到,输出流变为空。

c:\YourDir>cd > nul 1>&2
c:\YourDir

You get the std outout which has been sent to the error stream so it doesn't get redirected.

您获得已发送到错误流的 std 输出,因此它不会被重定向。

c:\YourDir>cd > nul 1<&2

This seams to do the same as 1>&2

这接缝与 1>&2 相同