Documentation ¶
Index ¶
- func IsTerminatedExitErr(err error) bool
- type Cmd
- func (c *Cmd) Run() error
- func (c *Cmd) Start() error
- func (c *Cmd) StderrTeePipe(writer io.Writer) (io.ReadCloser, error)
- func (c *Cmd) StdoutTeePipe(writer io.Writer) (io.ReadCloser, error)
- func (c *Cmd) TerminateProcessGroup() error
- func (c *Cmd) TerminatedAfterContextDone() bool
- func (c *Cmd) Wait() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTerminatedExitErr ¶ added in v0.2.0
IsTerminatedExitErr returns true if the error is the expected error when the process was terminated via Cmd.TerminateProcessGroup and the process exited within the grace period.
On Unix, multiple errors can happen when a SIGTERM is sent to the process group:
- The process can have exit code 143, which is the expected exit code when a process receives a SIGTERM
- The process can have exit code -1 and the signal of the wait status set to SIGTERM
- In case that the process doesn't handle the SIGTERM fast enough and tries to write to the pipe which was already closed by TerminateProcessGroup, the process has exit code -1 and the signal of the wait status is set to SIGPIPE
Types ¶
type Cmd ¶
Cmd provides the same functionality as exec.Cmd plus some utility methods.
func CommandContext ¶
CommandContext is like Command but includes a context.
The provided context is used to terminate the process group (by first sending SIGTERM to the process group and after a grace period of 3 seconds SIGKILL) if the context becomes done before the command completes on its own. In that case, Cmd.TerminatedAfterContextDone() returns true.
func (*Cmd) Start ¶
Does the same as exec.Cmd.Start(), but also closes the write ends of tee pipes (if there are any) on the same errors that exec.Cmd.Start() closes its open pipes.
func (*Cmd) StderrTeePipe ¶
Same as StdoutTeePipe but for stderr.
func (*Cmd) StdoutTeePipe ¶
StdoutTeePipe is similar to StdoutPipe, but everything written to the pipe is also copied to the specified writer (similar to tee(1)).
In contrast to StdoutPipe, Wait will *not* automatically close the pipe, so it's the caller's responsibility to close the pipe. In effect, it is fine to call Wait before all reads from the pipe have completed.