Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exec ¶
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.