child

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// Command is the name of the command to execute. Args holds the command
	// arguments, if any.
	Name string
	Args []string

	// Stdin, Stdout, and Stderr represent the respective data streams that the
	// command may act upon. They are attached directly to the child process.
	Stdin          io.Reader
	Stdout, Stderr io.Writer

	// Env specifies the environment of the process. Only these environment
	// variables will be given to the command, so it is the responsibility of
	// the caller to include the parent processes environment, if required.
	// Each entry should be of the form "key=value".
	Env []string

	// Path is the path of the command to run. If Path is relative, it is
	// evaluated relative to Dir.
	Path string

	// Dir specifies the working directory of the command. If Dir is the
	// empty string, Run runs the command in the calling process's current
	// directory.
	Dir string
	// contains filtered or unexported fields
}

Command represents an external command being prepared or run.

func NewCommand

func NewCommand(cmd string, options ...CommandOption) *Command

NewCommand creates a new Command.

func (*Command) CombinedOutput

func (x *Command) CombinedOutput(ctx context.Context) ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and

standard error.

func (*Command) ExitStatus

func (x *Command) ExitStatus() int

ExitStatus returns the exit status of the process.

func (*Command) Pid

func (x *Command) Pid() uint32

Pid yields the pid of the process (dead or alive), or 0 if the process has not been run yet.

func (*Command) Run

func (x *Command) Run(ctx context.Context) error

Run calls Start(), then Wait(), and returns an error (if any). The error may be of many types including *exec.ExitError and context.Canceled, context.DeadlineExceeded.

func (*Command) Runtime

func (x *Command) Runtime() time.Duration

Runtime returns the amount of time the process is or was running.

func (*Command) Start

func (x *Command) Start(ctx context.Context) error

Start starts the specified command but does not wait for it to complete.

func (*Command) Wait

func (x *Command) Wait(ctx context.Context) error

Wait waits for the command to exit and waits for any copying to stdin or copying from stdout or stderr to complete.

type CommandOption

type CommandOption func(*Command) error

CommandOption sets an optional parameter for commands.

func WithArgs

func WithArgs(args ...string) CommandOption

WithArgs specifies the command arguments.

func WithDir

func WithDir(dir string) CommandOption

WithDir specifies the working directory of the command.

func WithEnv

func WithEnv(env []string) CommandOption

WithEnv specifies the environment of the process created by the command.

func WithPath

func WithPath(path string) CommandOption

WithPath specifies the path of the command to run from.

func WithStdio

func WithStdio(in io.Reader, out, err io.Writer) CommandOption

WithStdio specifies the standard input, output and error files data streams.

Jump to

Keyboard shortcuts

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