exec

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package exec wraps the os/exec package. It facilitates testing by use of the sub-packge fake.

Example

var buf bytes.Buffer
c := Command("echo", "bob")
c.SetStdout(&buf)
err := c.Run()

Index

Constants

This section is empty.

Variables

View Source
var Command func(cmd string, args ...string) Cmd = NewCommand

Command is a variable that normally points to NewCommand. It is a variable so tests can redirect calls to a fake.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	SetStdout(io.Writer) // Redirect standard output to the writer
	SetStderr(io.Writer) // Redirect standard error to the writer
	SetStdin(io.Reader)  // Redirect standard in to the reader
	Run() error          // Operates the same as os/exec/Cmd.Run
}

A Cmd is an interface representing a command to run.

func NewCommand

func NewCommand(cmd string, args ...string) Cmd

NewCommand returns a Cmd that can run the supplied command. NewCommand sets up stdout and stderr to go to os.Stdout and os.Stderr. SetStdout and SetStderr are used to change where to send the output.

Most programs should use exec.Command rather than exec.NewCommand.

Directories

Path Synopsis
Package fake is used to fake calls github.com/openconfig/kne/exec.
Package fake is used to fake calls github.com/openconfig/kne/exec.

Jump to

Keyboard shortcuts

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