github.com/docker-library/go-dockerlibrary@v0.0.0-20200821205225-669fbe5c1d52/pkg/execpipe/execpipe_example_test.go (about)

     1  package execpipe_test
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"io"
     7  	"strings"
     8  
     9  	"github.com/docker-library/go-dockerlibrary/pkg/execpipe"
    10  )
    11  
    12  func Example() {
    13  	pipe, err := execpipe.RunCommand("go", "version")
    14  	if err != nil {
    15  		panic(err)
    16  	}
    17  	defer pipe.Close()
    18  
    19  	var buf bytes.Buffer
    20  	io.Copy(&buf, pipe)
    21  
    22  	fmt.Println(strings.SplitN(buf.String(), " version ", 2)[0])
    23  
    24  	// Output:
    25  	// go
    26  }