Working with standard input and output
In Linux/Unix, streams are communication channels between a process and its environment. By default, three standard streams are created for every running process: standard input, standard output, and standard error. A stream is a communication channel that has two ends. One end is connected to the process and the other end to another system resource. For example, a standard input can be used by a process to read characters or text from a keyboard or another process. Similarly, a standard output stream can be used by a process to send some characters to the terminal or to a file. In many modern programs, the standard error of a process is connected to a log file, which makes analyzing and debugging errors easier.
The Rust Standard Library provides methods to interact with standard input and output streams. The Stdin
struct in the std::io
module represents the handle to the input stream of a process. This handle implements the Read
trait, which...