execpipe

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Example
package main

import (
	"bytes"
	"fmt"
	"io"
	"strings"

	"github.com/docker-library/bashbrew/pkg/execpipe"
)

func main() {
	pipe, err := execpipe.RunCommand("go", "version")
	if err != nil {
		panic(err)
	}
	defer pipe.Close()

	var buf bytes.Buffer
	io.Copy(&buf, pipe)

	fmt.Println(strings.SplitN(buf.String(), " version ", 2)[0])

}
Output:

go

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pipe

type Pipe struct {
	// contains filtered or unexported fields
}

"io.ReadCloser" interface to a command's output where "Close()" is effectively "Wait()"

func Run

func Run(cmd *exec.Cmd) (*Pipe, error)

start "cmd", capturing stdout in a pipe (be sure to call "Close" when finished reading to reap the process)

func RunCommand

func RunCommand(cmd string, args ...string) (*Pipe, error)

convenience wrapper for "Run"

func (*Pipe) Close

func (pipe *Pipe) Close() error

func (*Pipe) Read

func (pipe *Pipe) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL