在Windows中,2&1的区别是什么?

时间:2022-07-06 23:09:30

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

找到文件。txt,然后重定向处理1(即,STDOUT)并处理2(即STDERR)到搜索。三种类型:findfile file.txt >搜索。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),然后将输出重定向到输出。日志,类型:ipconfig.exe > >输出。日志2 > & 1

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

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

1 个解决方案

#1


10  

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输出流,它变为null。

c:\YourDir>cd > nul

You get nothing, the output stream goes to null.

你得不到任何东西,输出流变为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 outout发送到错误流中,这样它就不会被重定向。

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

This seams to do the same as 1>&2

这个接缝和1>和2一样。

#1


10  

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输出流,它变为null。

c:\YourDir>cd > nul

You get nothing, the output stream goes to null.

你得不到任何东西,输出流变为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 outout发送到错误流中,这样它就不会被重定向。

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

This seams to do the same as 1>&2

这个接缝和1>和2一样。