exec

package
v0.0.0-...-950aede Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package exec provides command execution related helpers and utilities.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = exec.ErrNotFound

ErrNotFound re-exports exec.ErrNotFound for convenience.

Functions

func RunAttachedCommand

func RunAttachedCommand(name string, opts ...CommandOption) error

RunAttachedCommand is a convenience alias for RunCommand where WithAttachedPipes is appended to the provided options.

func RunAttachedCommandContext

func RunAttachedCommandContext(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) error

RunAttachedCommandContext is a convenience alias for RunCommandContext where WithAttachedPipes is appended to the provided options. If the given context is done before the command returns, the command will be killed.

func RunCommand

func RunCommand(name string, opts ...CommandOption) error

RunCommand runs the given program or executable with the given options.

func RunCommandCombinedOutput

func RunCommandCombinedOutput(
	name string,
	opts ...CommandOption,
) (string, error)

RunCommandCombinedOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error combined.

func RunCommandContext

func RunCommandContext(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) error

RunCommandContext runs the given program or executable with the given options. If the given context is done before the command returns, the command will be killed.

func RunCommandContextCombinedOutput

func RunCommandContextCombinedOutput(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) (string, error)

RunCommandContextCombinedOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error combined. If the given context is done before the command returns, the command will be killed.

func RunCommandContextOutput

func RunCommandContextOutput(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) (string, error)

RunCommandContextOutput calls RunCommand with the given name and options, and returns the command's standard output. If the given context is done before the command returns, the command will be killed.

func RunCommandContextSplitOutput

func RunCommandContextSplitOutput(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) (string, string, error)

RunCommandContextSplitOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error individually. If the given context is done before the command returns, the command will be killed.

func RunCommandOutput

func RunCommandOutput(name string, opts ...CommandOption) (string, error)

RunCommandOutput calls RunCommand with the given name and options, and returns the command's standard output.

func RunCommandSplitOutput

func RunCommandSplitOutput(
	name string,
	opts ...CommandOption,
) (string, string, error)

RunCommandSplitOutput calls RunCommand with the given name and options, and returns the command's standard output and standard error individually.

func RunSilentCommand

func RunSilentCommand(name string, opts ...CommandOption) error

RunSilentCommand is a convenience alias for RunCommand where WithNopPipes is appended to the provided options.

func RunSilentCommandContext

func RunSilentCommandContext(
	ctx context.Context,
	name string,
	opts ...CommandOption,
) error

RunSilentCommandContext is a convenience alias for RunCommand where WithNopPipes is appended to the provided options. If the given context is done before the command returns, the command will be killed.

Types

type CommandOption

type CommandOption = func(*exec.Cmd)

A CommandOption specializes the behavior of RunCommand and its variants.

func CommandOptions

func CommandOptions(opts ...CommandOption) CommandOption

CommandOptions combines multiple CommandOption to specialize RunCommand and its variants.

func WithArgs

func WithArgs(args ...string) CommandOption

WithArgs returns a new CommandOption that uses the given args as command arguments.

func WithAttachedPipes

func WithAttachedPipes() CommandOption

WithAttachedPipes returns a new CommandOption that uses this program's standard output, standard error, and standard input.

func WithDir

func WithDir(dir string) CommandOption

WithDir returns a new CommandOption that uses the given dir as as the working directory.

func WithEnv

func WithEnv(env []string) CommandOption

WithEnv returns a new CommandOption that uses the given key=val pairs as the environment.

func WithNopPipes

func WithNopPipes() CommandOption

WithNopPipes returns a new CommandOption that uses nop types for standard output, standard error, and standard input.

func WithStderr

func WithStderr(w io.Writer) CommandOption

WithStderr returns a new CommandOption that uses w for standard error.

func WithStdin

func WithStdin(r io.Reader) CommandOption

WithStdin returns a new CommandOption that uses w for standard input.

func WithStdout

func WithStdout(w io.Writer) CommandOption

WithStdout returns a new CommandOption that uses w for standard output.

type Error

type Error = exec.Error

Error re-exports exec.Error for convenience.

type ExitError

type ExitError = exec.ExitError

ExitError re-exports exec.ExitError for convenience.

Jump to

Keyboard shortcuts

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