pipe

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pipe extends os.exec, making it easier to create pipes to subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

Cmd is drop-in replacement for exec.Cmd, extended with the Pipe method.

func CommandContext

func CommandContext(ctx context.Context, name string, arg ...string) *Cmd

CommandContext returns a new Cmd. See exec.CommandContext for details.

func (*Cmd) Cleanup

func (c *Cmd) Cleanup()

Cleanup cleans up any unused resources.

func (*Cmd) RPipe

func (c *Cmd) RPipe() (int, io.ReadCloser, error)

RPipe returns the reading side of a pipe that will be connected to the subprocess when the command starts.

The subprocess can write to the pipe using the file descriptor returned by RPipe. Cmd.ExtraFiles should not be modified directly if RPipe is called.

Wait will close the pipe after seeing the command exit, so most callers need not close the pipe themselves. It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to use Run when using Pipe. See the exec.Cmd.StdoutPipe example 1 for idiomatic usage.

func (*Cmd) Start

func (c *Cmd) Start() error

Start is identical to exec.Command.Start.

func (*Cmd) WPipe

func (c *Cmd) WPipe() (int, io.WriteCloser, error)

WPipe returns the writer side of a pipe that will be connected to the subprocess when the command starts.

The subprocess can read from the pipe using the file descriptor returned by WPipe. Cmd.ExtraFiles should not be modified directly if WPipe is called.

The pipe will be closed automatically after Wait sees the command exit. A caller need only call Close to force the pipe to close sooner. For example, if the command being run will not exit until standard input is closed, the caller must close the pipe.

func (*Cmd) Wait

func (c *Cmd) Wait() error

Wait is identical to exec.Command.Wait.

Jump to

Keyboard shortcuts

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