exec

package
v3.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCmdOpts = CmdOpts{
	Timeout:          time.Duration(0),
	FatalTimeout:     time.Duration(0),
	Redactor:         Unredacted,
	TimeoutBehavior:  TimeoutBehavior{syscall.SIGKILL, false},
	SkipErrorLogging: false,
	CaptureStderr:    false,
}
View Source
var (
	Unredacted = Redact(nil)
)

Functions

func GetCommandArgsToLog

func GetCommandArgsToLog(cmd *exec.Cmd) string

GetCommandArgsToLog represents the given command in a way that we can copy-and-paste into a terminal

func Redact added in v3.1.0

func Redact(items []string) func(text string) string

func Run

func Run(cmd *exec.Cmd) (string, error)

func RunCommand added in v3.1.0

func RunCommand(name string, opts CmdOpts, arg ...string) (string, error)

func RunCommandExt added in v3.1.0

func RunCommandExt(cmd *exec.Cmd, opts CmdOpts) (string, error)

RunCommandExt is a convenience function to run/log a command and return/log stderr in an error upon failure.

func RunWithExecRunOpts

func RunWithExecRunOpts(cmd *exec.Cmd, opts ExecRunOpts) (string, error)

func RunWithRedactor

func RunWithRedactor(cmd *exec.Cmd, redactor func(text string) string) (string, error)

Types

type CmdError added in v3.1.0

type CmdError struct {
	Args   string
	Stderr string
	Cause  error
}

func (*CmdError) Error added in v3.1.0

func (ce *CmdError) Error() string

func (*CmdError) String added in v3.1.0

func (ce *CmdError) String() string

type CmdOpts added in v3.1.0

type CmdOpts struct {
	// Timeout determines how long to wait for the command to exit
	Timeout time.Duration
	// FatalTimeout is the amount of additional time to wait after Timeout before fatal SIGKILL
	FatalTimeout time.Duration
	// Redactor redacts tokens from the output
	Redactor func(text string) string
	// TimeoutBehavior configures what to do in case of timeout
	TimeoutBehavior TimeoutBehavior
	// SkipErrorLogging defines whether to skip logging of execution errors (rc > 0)
	SkipErrorLogging bool
	// CaptureStderr defines whether to capture stderr in addition to stdout
	CaptureStderr bool
}

type ExecRunOpts

type ExecRunOpts struct {
	// Redactor redacts tokens from the output
	Redactor func(text string) string
	// TimeoutBehavior configures what to do in case of timeout
	TimeoutBehavior TimeoutBehavior
	// SkipErrorLogging determines whether to skip logging of execution errors (rc > 0)
	SkipErrorLogging bool
	// CaptureStderr determines whether to capture stderr in addition to stdout
	CaptureStderr bool
}

type TimeoutBehavior added in v3.1.0

type TimeoutBehavior struct {
	// Signal determines the signal to send to the process
	Signal syscall.Signal
	// ShouldWait determines whether to wait for the command to exit once timeout is reached
	ShouldWait bool
}

TimeoutBehavior defines behavior for when the command takes longer than the passed in timeout to exit By default, SIGKILL is sent to the process and it is not waited upon

Jump to

Keyboard shortcuts

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