Reputation: 2291
Many articles on the internet use the "Standard Input/Output/Error Stream" term as if each of the term has the same meaning with the "Standard Input/Output/Error Device" term used on other articles. For example, many articles say that the Standard Output Stream is the monitor by default but can be redirected to a file, printer, or other devices.
Let's take the standard output as the example:
What is the difference between the standard output stream and the standard output device? If there is one, what is the relation between them?
Quoted from the help page of GetStdHandle(),
"The standard handles of a process may be redirected by a call to SetStdHandle, in which case GetStdHandle returns the redirected handle."
Which one is redirected actually, the standard output stream or the standard output device?
Does each process has its own standard streams?
Upvotes: 2
Views: 1943
Reputation: 5126
An output device is some logical entity to which data can be written.
An output stream is a connection to an output device.
In a process, you have a standard output stream, which is connected to your standard output device. That means writing data to your standard output stream will output it to the standard output device. Of course, you can actually change to which device the stream is bound after the process has started.
To answer your last question, the answer is yes, each process has its own standard stream. Which device this actually maps to depends on the operating system and how the process was started. As an example, any process started directly from the console in Linux or Windows has its standard output stream linked to that console by default. However, this stream can be redirected by using either ">" to refer to a hardware device or file, or by "piping", which can be used to make a series of programs redirect their standard output streams to each other.
For example:
echo hi > example.txt
would start the program "echo" with argument "hi" and set the standard output stream to the file "example.txt".
Analogously, each process also has a standard input stream and a standard error (output) stream.
Upvotes: 7