Documentation ¶
Index ¶
- type Command
- func (x *Command) CombinedOutput(ctx context.Context) ([]byte, error)
- func (x *Command) ExitStatus() int
- func (x *Command) Pid() uint32
- func (x *Command) Run(ctx context.Context) error
- func (x *Command) Runtime() time.Duration
- func (x *Command) Start(ctx context.Context) error
- func (x *Command) Wait(ctx context.Context) error
- type CommandOption
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 ¶
CombinedOutput runs the command and returns its combined standard output and
standard error.
func (*Command) ExitStatus ¶
ExitStatus returns the exit status of the process.
func (*Command) Pid ¶
Pid yields the pid of the process (dead or alive), or 0 if the process has not been run yet.
func (*Command) Run ¶
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.
type CommandOption ¶
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.