Programming Unix pipes in Go

According to the Unix philosophy, Unix command-line utilities should do one job and perform that job well! In practice, this means that instead of developing huge utilities that do lots of jobs, you should develop multiple smaller programs, which when combined, should perform the desired job. The most common way for two or more Unix command-line utilities to communicate is by using pipes. In a Unix pipe, the output of a command-line utility becomes the input of another command-line utility. This process may involve more than two programs! The symbol that is used for Unix pipes is the | character.

Pipes have two serious limitations: first, they usually communicate in one direction, and second, they can only be used between processes that have a common ancestor. The general idea behind the implementation of Unix pipes is that if you do not have a file to process, you should wait to get your input from standard input. Similarly, if you are not told to save your output to a file, you should write your output to standard output, either for the user to see it or for another program to process it.

In Chapter 1, Go and the Operating System, you learned how to read from standard input and how to write to standard output. If you have doubts about these two operations, it would be a good time to review the Go code of stdOUT.go and stdIN.go.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.23.147