Go package for executing external commands with retries, timeouts, and output collection.
- Attempt timeouts - Kill commands that run too long
- Total timeouts - Limit total time including retries
- Automatic retries - Retry on timeout with configurable filters
- Output collection - Capture stdout, stderr, and combined output
- Reset timeout on output - Keep alive commands that produce output
- Fluent API - Builder pattern for clean configuration
go get github.com/GiGurra/cmderresult := cmder.New("ls", "-la").
WithAttemptTimeout(5 * time.Second).
WithRetries(3).
Run(context.Background())
if result.Err != nil {
fmt.Printf("Failed: %v\n", result.Err)
} else {
fmt.Printf("Output: %s\n", result.StdOut)
}result := cmder.New("slow-command").
WithAttemptTimeout(30 * time.Second).
Run(ctx)result := cmder.New("flaky-service").
WithRetries(5).
WithAttemptTimeout(10 * time.Second).
Run(ctx)// Timeout resets each time command produces output
result := cmder.New("long-running-task").
WithAttemptTimeout(5 * time.Second).
WithResetAttemptTimeoutOnOutput(true).
Run(ctx)result := cmder.New("build-script").
WithStdOutErrForwarded(). // Print to terminal
Run(ctx)result := cmder.New("api-call").
WithRetries(3).
WithRetryFilter(func(err error, isTimeout bool) bool {
return isTimeout // Only retry timeouts
}).
Run(ctx)See the API documentation for full details.
MIT