Pipe design for command-line tools
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 an input line by line via the standard input pipe, process it in some way, and then print the output line by line to the standard out pipe for the next tool or user.
By default, the standard input is connected to the user's keyboard, and the standard output is printed to the terminal from where 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 that will cause the output to be saved to a disk. Alternatively, you can pipe (using the |
pipe character) the output of one program to 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 pipe...