local

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 New

func New() *Executor

New returns a local command executor.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL