Go Cookbook
上QQ阅读APP看书,第一时间看更新

Working with Unix pipes

Unix pipes are useful when passing the output of one program to the input of another. For example, take a look at this:

$ echo "test case" | wc -l
1

In a Go application, the left-hand side of the pipe can be read in using os.Stdin and acts like a file descriptor. To demonstrate this, this recipe will take an input on the left-hand side of a pipe and return a list of words and their number of occurrences. These words will be tokenized on white space.