exec

package
v1.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(cmd *exec.Cmd) ([]byte, error)

Exec is a custom replacement for cmd.CombinedOutput(). It executes the provided command and returns the command's combined output (stdout + stderr) and an error. When the command completes successfully, with a non-zero exit code, the error is nil. If the command's exit code is non-zero, the error is of type ExitError. Other, unanticipated errors are wrapped and returned as-is. The primary benefit to calling Exec() over calling cmd.CombinedOutput() directly is that errors will automatically include command output, which is likely to contain important information about the cause of the error.

Types

type ExitError

type ExitError struct {
	// Command is the command that caused the error.
	Command string
	// Output is the combined output (stdout and stderr) produced when Command was
	// executed.
	Output []byte
	// ExitCode is the exit code that was returned when Command was executed.
	ExitCode int
}

ExitError is an error type that is produced by the Exec() function when a command returns a non-zero exit code.

func (*ExitError) Error

func (e *ExitError) Error() string

Jump to

Keyboard shortcuts

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