Documentation
¶
Overview ¶
Package local implements executor.Executor for the local machine with os/exec.
The context passed to Start owns the child's lifetime: when it ends the child is killed, or first asked to terminate when Command.KillGrace is positive. With Command.ProcessGroup set, Signal, Kill and cancellation reach the whole process group (Unix) or Job Object (Windows). Contexts passed to Wait, Signal, Kill and Export bound only that call.
The package supports Windows and the Unix-like targets aix, android, darwin, dragonfly, freebsd, linux, netbsd, openbsd and solaris.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor struct{}
Executor starts commands on the local machine. The zero value is ready to use, and an Executor is safe for concurrent use.
Example (BoundedRun) ¶
first, err := exampleCommand("delay")
if err != nil {
fmt.Println("error")
return
}
second, err := exampleCommand("success")
if err != nil {
fmt.Println("error")
return
}
results, err := executor.RunAll(
context.Background(),
New(),
[]executor.Command{first, second},
2,
)
if err != nil {
fmt.Println("error")
return
}
for _, result := range results {
fmt.Printf("%s %d\n", strings.TrimSpace(string(result.Stdout)), result.ExitCode)
}
Output: delayed 0 out 0
func (*Executor) Run ¶
func (executorInstance *Executor) Run(ctx context.Context, command executor.Command) (executor.Result, error)
Run starts command and waits until it has been reaped. The start context may terminate the child, but it does not interrupt the reap operation.
Example ¶
command, err := exampleCommand("success")
if err != nil {
fmt.Println("error")
return
}
result, err := New().Run(context.Background(), command)
if err != nil {
fmt.Println("error")
return
}
fmt.Print(string(result.Stdout))
fmt.Println(result.ExitCode)
Output: out 0
func (*Executor) Start ¶
func (executorInstance *Executor) Start(ctx context.Context, command executor.Command) (executor.Process, error)
Start validates and starts command. The supplied context owns process cancellation for the lifetime of the child: when it ends, the child (or its process group when Command.ProcessGroup is set) is killed, or first asked to terminate when Command.KillGrace is positive.