该包使得 Go 应用程序能够像 Unix 中的 pipe 一样使用。
The pipe Go package offers an easy way for Go programs to make use of other applications available in the system via a Unix-like pipeline mechanism. The input and output streams in such pipelines do work as streams, so large content can go across the pipeline without being loaded entirely in memory.
The following blog post introduces the concept: http://blog.labix.org/2013/04/15/unix-like-pipelines-for-go
简单例子:
package main
import (
"fmt"
"gopkg.in/pipe.v2"
)
func main() {
p := pipe.Line(
pipe.ReadFile("article.ps"),
pipe.Exec("lpr"),
)
output, err := pipe.CombinedOutput(p)
if err != nil {
fmt.Printf("%v\n", err)
}
fmt.Printf("%s", output)
}