exec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	WorkingDir *string
	LogPath    *string
	// contains filtered or unexported fields
}

Context is a set of information surrounding how to execute a certain executable. It provides utilities for executing the same executable multiple times with the same working directory and log path, and allows for adding files to the working directory, setting the environment, and retrieving log files.

func NewContext

func NewContext(executablePath string, logPath, workingDir *string, envVars map[string]string) (*Context, error)

func (*Context) AddFile

func (ec *Context) AddFile(filename string, content []byte) error

AddFile adds a new file with the contents to the working directory of the Context.

func (*Context) Exec

func (ec *Context) Exec(stdout, stderr io.Writer, cleanup func(), args ...string) (*Result, error)

Exec begins executing the executable, and returns a Result containing the Pid of the process, as well as a function that will wait for the process to complete and clean up, returning an error if the process failed. Exec will forward stdout and stderr of the spawned process to the respective io.Writers passed in. cleanup should do any extra cleanup necessary required by the calling function (such as closing a log file that stdout/stderr are being piped to). If there is no cleanup to be done, nil may be passed.

func (*Context) ExecSync

func (ec *Context) ExecSync(args ...string) (string, string, error)

ExecSync blocks while executing, and returns stdout and stderr.

func (*Context) ExecWithLogFile

func (ec *Context) ExecWithLogFile(logPrefix string, args ...string) (*Result, string, error)

ExecWithLogFile runs Exec, piping stdout and stderr to a log file which is created in the LogPath of the exec context, whose filename will be logPrefix-<generated-UUID>.log. ExecWithLogFile returns the Result from Exec, along with the log's filename.

func (*Context) ExecWithLogFileSync

func (ec *Context) ExecWithLogFileSync(logPrefix string, args ...string) (string, error)

ExecWithLogFileSync runs ExecWithLogFile but blocks until the process has completed, returning the log filename.

func (*Context) LogFile

func (ec *Context) LogFile(logFilename string) (io.ReadCloser, error)

LogFile returns an io.ReadCloser for the log file with the given logFilename in the LogPath.

func (*Context) SetEnvVars

func (ec *Context) SetEnvVars(envVars map[string]string)

SetEnvVars overrides the existing EnvVars for the

type Result

type Result struct {
	Pid  int
	Wait func() error
}

Jump to

Keyboard shortcuts

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