A program can write two kinds of text:
- Its normal output: the text of a file, a list of names, a count.
- Error messages: what went wrong.
The program writes each kind on its own channel, a stream:
| Stream | Short name | Carries |
|---|---|---|
| Standard output | stdout | The normal output |
| Standard error | stderr | The error messages |
cat prices.txt missing.txt
stdoutstderr
Terminal
They look the same
Both streams go to the terminal, so you cannot see the difference:
text
learner@tidepool:~$ cat prices.txt missing.txt
tea 4.50
coffee 3.20
cat: missing.txt: No such file or directorytea 4.50andcoffee 3.20are on standard output.cat: missing.txt: ...is on standard error. Error messages start with the name of the program, as you learned in "Read an Error Message".
Why two streams?
Because they are separate, you can send them to different places. You can save the output in a file and still see the errors on the screen. Or save the errors and hide the output. The next lessons show how.