command

package
v0.0.0-...-9933dd3 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandEmpty            = errors.New("command is empty")
	ErrSingleQuoteUnterminated = errors.New("unterminated single-quoted string")
	ErrDoubleQuoteUnterminated = errors.New("unterminated double-quoted string")
	ErrEscapeUnterminated      = errors.New("unterminated backslash-escape")
)

Functions

func Split

func Split(command string) (words []string, err error)

Split splits a command string into a slice of arguments. This is especially important for commands such as: /bin/sh -c "echo hello" which should be split into: ["/bin/sh", "-c", "echo hello"] It supports backslash-escapes, single-quotes and double-quotes. It does not support: - the $" quoting style. - expansion (brace, shell or pathname).

Types

type Cmder

type Cmder struct{}

Cmder handles running subprograms synchronously and asynchronously.

func New

func New() *Cmder

func (*Cmder) Run

func (c *Cmder) Run(cmd *exec.Cmd) (output string, err error)

Run runs a command in a blocking manner, returning its output and an error if it failed.

func (*Cmder) Start

func (c *Cmder) Start(cmd *exec.Cmd) (
	stdoutLines, stderrLines <-chan string,
	waitError <-chan error, startErr error,
)

Start launches a command and streams stdout and stderr to channels. All the channels returned are ready only and won't be closed if the command fails later.

Jump to

Keyboard shortcuts

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