About
Standard Streams are the mechanism by which a process:
- receive data (stdin)
- and output data (stdout, stderr).
At the command line (Repl, Shell)
In a shell, by default, they will:
- read input from the keyboard
- and write output to the display.
They are the building block of interaction with the user in a command line environment. The application catch them and manipulate them to interact with the user or other programs.
List
The three I/O connections are called:
- standard input (stdin) - Read from the keyboard or from a redirection such as the pipe.
- standard output (stdout) - Print to the display and can be redirected as standard input.
- and standard error (stderr) - Same as stdout but normally only for errors. Having error output separately allows the user to divert regular output to a file and still be able to read error messages.
Implementation
They are open files that point to the standard input, standard output, and standard error file descriptors.
They are properties of every process
Language
Language | stdin | stdout | stderr |
---|---|---|---|
Java | System.in | System.out | System.err |
C | Unix file descriptors 0 | Unix file descriptors 1 | Unix file descriptors 2 |
Bash (Shell) | stdin | /dev/stdout | stderr |
Method
Redirection
Standard streams also support I/O on files and between programs, but that feature is controlled by the command line interpreter, not the program.