Standard streams

The standard data streams (English: standard streams) are three data streams for input and output in the operating system Unix or related operating systems. They are also supported by the standard C library. Many programs automatically use the default or standard output if no output file is specified for input or output on the command line.

Standard input ( stdin)

Apart from the standard input data can be read into a program. It is normally connected to the keyboard, which are programs receive user input from the standard input. On Unix, the standard input corresponds to the device file / dev / stdin, file descriptor has the number 0

Example: Here is the standard input for the less program from the file is read eingaben.txt.

$ Eingaben.txt less < Standard output ( stdout)

To the standard output, a program can output data. Normally it is connected to the monitor, which are programs send output texts on the standard output to the user. On Unix, the standard output corresponds to the device file / dev / stdout file descriptor has the number 1

Example: Here is the standard output of the program find in the file redirected ausgaben.txt.

The standard error is a second output stream, which is intended to output error and status messages. Normally, he is also connected to the monitor; However, it can be redirected separately from the standard output, so that error messages are not mixed with the output payload. On Unix, the standard error corresponding to the device file / dev / stderr, file descriptor has the number 2

Example 1: Here are the error messages reported by the place in the file redirected fehlermeldungen.txt, while the standard output is passed through a pipe to the program less.

Example 2: Redirect the error messages to stdout:

Example 3:

$ Find. -name '. * html' 2> & 1 1> gefundene.txt | less stderr is on the screen / Scrn: redirected, then stdout ' gefundene.txt ' in the file; stderr is not redirected with this in the file because it was not even directed " to stdout ", but " to where stdout is pointing (s)". The concatenation with less so causes the page by displaying the error messages.

Example 4:

$ Find. -name '. * html' 1> gefundene.txt 2> & 1 | less stdout is redirected gefundene.txt in the file, then stderr to where stdout is currently showing (thus also in the file ), for less any left over!

C and C

In the C programming three file pointers in the header file stdio.h the type FILE * with the name of stdin, stdout, and stderr are defined. These virtual files are usually opened automatically from program start and can with most commands that access files are used.

Under C reference is made to the iostream Library, which is part of the standard library. It is included with the header file iostream ( without file extension ), access to the standard data streams are finally on the cout stream object std :: std :: cin and std :: cerr.

Because this behavior of C or C is standardized, these standard data streams can also be found in non- Unix operating systems (like Windows) or be simulated accordingly.

Java programming language

In the Java language java.lang.System three streams are generated in the class. As System.in InputStream, PrintStream System.out as well as System.err and PrintStream. These streams are automatically opened at startup and can be used to access the standard streams. Because this behavior of Java is standardized, these standard data streams can also be found in non-Unix operating systems or be simulated accordingly.

Python

Even under Python can be accessed on the standard data streams, namely stdin with the file objects provided in the sys module, stdout, and stderr.

90104
de