pipe

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 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) MakePipePair added in v0.22.0

func (c *Cmd) MakePipePair() (PipePair, error)

MakePipePair makes a pair of pipes that can be used for bi-directional communication with the child process.

Cmd.ExtraFiles should not be modified directly if MakePipePair is called.

Wait will close ParentWriter automatically after seeing the command exit. A caller need only close ParentWriter 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 ParentWriter.

Wait will close ParentReader automatically after seeing the command exit, so most callers need not close ParentReader themselves. It is thus incorrect to call Wait before all reads from ParentReader have completed. For the same reason, it is incorrect to use Run when using MakePipePair. 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) Wait

func (c *Cmd) Wait() error

Wait is identical to exec.Command.Wait.

type PipePair added in v0.22.0

type PipePair struct {
	ParentReader io.ReadCloser  // Reader from which parent can read
	ParentWriter io.WriteCloser // Writer to which parent can write
	ChildReader  uintptr        // Descriptor from which child can read
	ChildWriter  uintptr        // Descriptor to which child can write
}

PipePair holds a pair of pipes that can be used for bi-directional communication with a child process.

Jump to

Keyboard shortcuts

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