Documentation
¶
Overview ¶
Package timeout implements a GNU-compatible timeout command.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // ExitSuccess is the exit code used for successful execution. ExitSuccess = 0 // ExitTimedOut is the exit code used when the command times out. ExitTimedOut = 124 // ExitInternalFailure is the exit code used for timeout's own failures. ExitInternalFailure = 125 // ExitCannotInvoke is the exit code used when a command cannot be invoked. ExitCannotInvoke = 126 // ExitNotFound is the exit code used when a command cannot be found. ExitNotFound = 127 )
Variables ¶
View Source
var ErrUsage = errors.New("usage error")
ErrUsage marks command-line usage errors.
Functions ¶
func ParseDuration ¶
ParseDuration parses GNU timeout duration syntax.
func ParseSignal ¶
ParseSignal parses a signal name, SIG-prefixed name, or signal number.
func Run ¶
Run runs timeout with the given arguments and streams and returns an exit code.
Example (Help) ¶
package main
import (
"bytes"
"fmt"
"github.com/KEINOS/go-timeout/timeout"
)
func main() {
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
code := timeout.Run([]string{"--help"}, timeout.Streams{
Stdout: stdout,
Stderr: stderr,
})
fmt.Println(code)
fmt.Println(stderr.String())
fmt.Println(stdout.String()[:6])
}
Output: 0 Usage:
Types ¶
type Config ¶
type Config struct {
Foreground bool
PreserveStatus bool
Verbose bool
ShowHelp bool
ShowVersion bool
Duration time.Duration
KillAfter time.Duration
Signal syscall.Signal
Command []string
}
Config contains parsed timeout options and operands.
func Parse ¶
Parse parses timeout command-line arguments.
Example ¶
package main
import (
"fmt"
"github.com/KEINOS/go-timeout/timeout"
)
func main() {
config, err := timeout.Parse([]string{"-k", "1s", "-s", "TERM", "2s", "printf", "ok"})
fmt.Println(err)
fmt.Println(config.KillAfter)
fmt.Println(config.Duration)
fmt.Println(config.Command)
}
Output: <nil> 1s 2s [printf ok]
Click to show internal directories.
Click to hide internal directories.