executil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 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

Index

Constants

This section is empty.

Variables

View Source
var ErrNoShell = errors.New("no command shell found")

Error of Shell and ShellCommand when the platform names no command shell

Functions

func ExitCode

func ExitCode(state *os.ProcessState) int

Exit code of a finished process, the negated signal number when a signal ended it, -1 for a nil state

func Shell

func Shell() (string, error)

Path of the POSIX shell, /system/bin/sh on Android and /bin/sh elsewhere

func ShellCommand

func ShellCommand(command string) (*exec.Cmd, error)

Command that runs a command line through the POSIX shell as sh -c command

func WindowsCommandLine

func WindowsCommandLine(args []string) string

Windows command line of the arguments on any host, each quoted so CommandLineToArgvW and the C runtime read it back unchanged

Types

type Completed

type Completed struct {
	Args     []string
	ExitCode int
	Stdout   []byte
	Stderr   []byte
}

Finished command with its exit code, the negated signal number when a signal ended it on Unix and -1 when it never ran, and both captured streams

func Run

func Run(ctx context.Context, argv []string, o Options) (*Completed, error)

Runs argv with both streams captured; the result comes back even beside an error, an expired Timeout kills the command and gives a *TimeoutError, a done ctx gives the ctx error

type Options

type Options struct {
	Dir            string
	Env            []string
	Input          []byte
	Timeout        time.Duration
	RequireSuccess bool
	Attr           *syscall.SysProcAttr
}

Settings of one Run: nil Env inherits the environment, nil Input reads the null device, a positive Timeout kills the command once it passes, RequireSuccess makes a non-zero exit a *StatusError

type StatusError

type StatusError struct {
	Args     []string
	ExitCode int
	Stdout   []byte
	Stderr   []byte
}

Non-zero exit of a command run with RequireSuccess, carrying its exit code and both captured streams

func (*StatusError) Error

func (e *StatusError) Error() string

The command and how it ended, as in command ["git" "fetch"]: exit status 128

type TimeoutError

type TimeoutError struct {
	Args    []string
	Timeout time.Duration
	Stdout  []byte
	Stderr  []byte
}

Command killed for outliving its timeout, carrying the timeout and the output read before the kill

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

The command and its timeout, as in command ["sleep" "5"] timed out after 1s

Jump to

Keyboard shortcuts

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