exec

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package exec provides useful wrappers around the standard "exec" library.

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 wraps exec.Cmd with a context to provide convenient execution of a command with nice checking of the context timeout in the form:

err := exec.Prog().WithTimeout(5*time.Second, myprog, myargs...).CombinedOutput(log, verbose)

func CommandContext

func CommandContext(ctx context.Context, prog string, args ...string) *Cmd

CommandContext wraps exec.CommandContext to allow this package to be used as a drop-in replacement for the standard exec library.

func WithCancel

func WithCancel(ctx context.Context, prog string, args ...string) (*Cmd, context.CancelFunc)

WithCancel creates a Cmd with a context that can be cancelled by calling the resulting Cancel() function.

func WithTimeout

func WithTimeout(timeout time.Duration, prog string, args ...string) *Cmd

WithTimeout creates a Cmd with a context that times out after the specified duration.

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput(scopedLog *logrus.Entry, verbose bool) ([]byte, error)

CombinedOutput runs the command and returns its combined standard output and standard error. Unlike the standard library, if the context is exceeded, it will return an error indicating so.

Logs any errors that occur to the specified logger.

func (*Cmd) WithFilters

func (c *Cmd) WithFilters(filters ...string) *Cmd

WithFilters modifies the specified command to filter any output lines from logs if they contain any of the substrings specified as arguments to this function.

Jump to

Keyboard shortcuts

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