简体   繁体   中英

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

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

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.

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

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

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

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.

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.

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

This seams to do the same as 1>&2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM