Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrKillFailed = errors.New("failed to kill process")
Functions ¶
This section is empty.
Types ¶
type Result ¶ added in v1.0.5
type Result struct {
StdOut bytes.Buffer
StdErr bytes.Buffer
Buf bytes.Buffer
ExitCode int
// contains filtered or unexported fields
}
func Spawn ¶
Spawn runs a command and captures its output. It creates a new process group, waits for the command to finish, and returns a Result. When no WithStdout or WithStderr option is provided, both streams are captured into a shared Result.Buf. If the context is cancelled, Spawn sends SIGTERM (followed by SIGKILL after KillDelay) to the entire process group.
Options can be provided to configure stdin, stdout, stderr redirection, environment variables, working directory, and kill timeout behaviour.
func (Result) Err ¶ added in v1.0.5
Err returns the original *exec.ExitError if the command exited with a non-zero status, otherwise nil.
type SpawnOption ¶ added in v1.0.5
type SpawnOption interface {
// contains filtered or unexported methods
}
SpawnOption configures the Spawn function.
func WithDir ¶ added in v1.0.5
func WithDir(dir string) SpawnOption
WithDir sets the working directory for the command.
func WithEnv ¶ added in v1.0.5
func WithEnv(env ...string) SpawnOption
WithEnv adds extra environment variables in KEY=VALUE format.
func WithKillDelay ¶ added in v1.0.5
func WithKillDelay(d time.Duration) SpawnOption
WithKillDelay sets the grace period between SIGTERM and SIGKILL when a command is cancelled. Defaults to 5 seconds.
func WithStderr ¶ added in v1.0.5
func WithStderr(w io.Writer) SpawnOption
WithStderr sets the standard error for the command. When set, Result.StdErr will not be populated and stdout is captured in Result.StdOut.
func WithStdin ¶ added in v1.0.5
func WithStdin(r io.Reader) SpawnOption
WithStdin sets the standard input for the command.
func WithStdout ¶ added in v1.0.5
func WithStdout(w io.Writer) SpawnOption
WithStdout sets the standard output for the command. When set, Result.StdOut will not be populated and stderr is captured in Result.StdErr.