runutil

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: MIT Imports: 7 Imported by: 4

README

GoDoc

runutil

Various useful tools for running and pipe-ing stuff outside of Go.

This library makes it very easy to execute complex sequences of executables mixing both go-specific filters and commands.

For example it is possible to run the following:

	res, err := RunPipe(input, "gzip", "-9")
	if err != nil {
		t.Errorf("failed to run test: %s", err)
		return
	}

	res, err = gzip.NewReader(res)
	if err != nil {
		t.Errorf("failed to run test: %s", err)
		return
	}

Reading from res in that example will return the exact same bytes as input, after having been compressed once, then decompressed.

If the command fails, the final Read() call will return the failure code, and allows correctly catching any problem (by default, go os/exec will only return the error when calling Wait(), which may result in errors not being catched).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandMissing = errors.New("command is missing")
)

Functions

func Run

func Run(arg ...string) error

Run is a very simple invokation of command run, with output forwarded to stdout

func RunGet

func RunGet(arg ...string) ([]byte, error)

RunGet executes the command and returns its output as a buffer

func RunJson

func RunJson(obj interface{}, arg ...string) error

RunJson executes the command and applies its output to the specified object, parsing json data

func RunPipe

func RunPipe(r io.Reader, arg ...string) (io.ReadCloser, error)

RunPipe runs a command, connecting both ends

func RunRead

func RunRead(arg ...string) (io.ReadCloser, error)

RunRead executes and returns the command's output as a stream

func RunWrite

func RunWrite(r io.Reader, arg ...string) error

RunWrite executed the command and passes r as its input

func Sh

func Sh(cmd string) error

Sh runs a shell command (linux only)

func ShQuote

func ShQuote(s string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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