简体   繁体   中英

How (and for what) do I use stream handles 3 to 9 in Windows and CMD?

In CMD documentation https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490982(v=technet.10) are mentioned handles from 3 to 9.
I've never seen them in real life.

Documentation reads:

These handles are defined individually by the application and are specific to each tool.

How are they used? And what for?

Are they all opened by default? Or I have to open them from script or program somehow? How do I use them with ReadFile and WriteFile ?

As your link states:

Handle    Numeric equivalent  Description
          of handle                      
========= =================== =======================================
STDIN         0               Keyboard input

STDOUT        1               Output to the Command Prompt window

STDERR        2               Error output to the Command Prompt window

UNDEFINED     3-9             These handles are defined individually
                              by the application and are specific to 
                              each tool.

A practical use in batch files is to read several source files in parallel:

See these references:
https://stackoverflow.com/a/28864990/6811411
Combining multiple text files into one
http://www.dostips.com/forum/viewtopic.php?f=3&t=3126

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