We are going to build a series of command-line tools that use the standard streams (stdin
and stdout
) to communicate with the user and with other tools. Each tool will take input line by line via the standard in pipe, process it in some way, and then print the output line by line to the standard out pipe for the next tool or for the user.
By default, the standard input is connected to the user's keyboard, and the standard output is printed to the terminal from which the command was run; however, both can be redirected using redirection metacharacters. It's possible to throw the output away by redirecting it to NUL
on Windows or /dev/null
on Unix machines, or redirecting it to a file, which will cause the output to be saved to the disk. Alternatively, you can pipe (using the |
pipe character) the output of one program into the input of another; it is this feature that we will make use of in order to connect our various tools together. For example, you could...