×
Jinxia Li

Standard Streams & I/O Redirection

No Comments

Standard Streams

In computer programming, standard streams are interconnected input and output communication channels between a process and it environments. The three input/out connections are called standard input, standard output and standard error. Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard stream abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the stand streams of its parent process.

Text terminal vs. Shell

text terminal, or often just terminal is a serial computer interface for text entry and display.

The system console is a text terminal used to operate a computer. Modern computers have a built-in keyboard and display for the console.

The fundamental type of application running on a text terminal is a command-line interpreter or shell.

Another important application type is that of the text editor.

A text terminal is like a file. Writing to the file displays the text and reading from the file produces what the user enters.

Even more advanced interactivity is provided with full-screen applications. Those applications completely control the screen layout; also they respond to key-pressing immediately. This mode is very useful for text editorsfile managers and web browsers.

Users generally know standard streams as input and output channels that handle data coming from an input device, or that write data from the application.

Streams may be used to chain applications, meaning that the output stream of one program can be redirected to be the input stream to another application. 

Standard input is a stream from which a program reads its input data. The program requests data transfers by use of the read operation. Not all programs require stream input. // For example, the dir and ls programs (which display file names contained in a directory) may take command-line arguments, but perform their operations without any stream data input.

Standard output is a stream to which a program writes its output data. The program requests data transfer with the write operation. // Not all programs generate output. For example, the file rename command (variously called mvmove, or ren) is silent on success.

Unless redirected, standard output is inherited from the parent process. In the case of an interactive shell, that is usually the text terminal which initiated the program.

Standard error is another output stream typically used by programs to output error messages or diagnostics. It is a stream independent of standard output and can be redirected separately.

Leave a Comment

Your email address will not be published. Required fields are marked *

By commenting you accept the Privacy Policy