exec

package
v0.0.0-...-e758773 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2011 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package exec runs external commands. It wraps os.StartProcess to make it easier to remap stdin and stdout, connect I/O with pipes, and do other adjustments.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = os.ErrorString("executable file not found in $PATH")

ErrNotFound is the error resulting if a path search failed to find an executable file.

Functions

func LookPath

func LookPath(file string) (string, os.Error)

LookPath searches for an executable binary named file in the directories named by the PATH environment variable. If file contains a slash, it is tried directly and the PATH is not consulted.

Types

type Cmd

type Cmd struct {
	// Path is the path of the command to run.
	//
	// This is the only field that must be set to a non-zero
	// value.
	Path string

	// Args holds command line arguments, including the command as Args[0].
	// If the Args field is empty or nil, Run uses {Path}.
	//
	// In typical use, both Path and Args are set by calling Command.
	Args []string

	// Env specifies the environment of the process.
	// If Env is nil, Run uses the current process's environment.
	Env []string

	// Dir specifies the working directory of the command.
	// If Dir is the empty string, Run runs the command in the
	// calling process's current directory.
	Dir string

	// Stdin specifies the process's standard input.
	// If Stdin is nil, the process reads from DevNull.
	Stdin io.Reader

	// Stdout and Stderr specify the process's standard output and error.
	//
	// If either is nil, Run connects the
	// corresponding file descriptor to /dev/null.
	//
	// If Stdout and Stderr are are the same writer, at most one
	// goroutine at a time will call Write.
	Stdout io.Writer
	Stderr io.Writer

	// Process is the underlying process, once started.
	Process *os.Process
	// contains filtered or unexported fields
}

Cmd represents an external command being prepared or run.

func Command

func Command(name string, arg ...string) *Cmd

Command returns the Cmd struct to execute the named program with the given arguments.

It sets Path and Args in the returned structure and zeroes the other fields.

If name contains no path separators, Command uses LookPath to resolve the path to a complete name if possible. Otherwise it uses name directly.

The returned Cmd's Args field is constructed from the command name followed by the elements of arg, so arg should not include the command name itself. For example, Command("echo", "hello")

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, os.Error)

CombinedOutput runs the command and returns its combined standard output and standard error.

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, os.Error)

Output runs the command and returns its standard output.

func (*Cmd) Run

func (c *Cmd) Run() os.Error

Run starts the specified command and waits for it to complete.

The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.

If the command fails to run or doesn't complete successfully, the error is of type *os.Waitmsg. Other error types may be returned for I/O problems.

func (*Cmd) Start

func (c *Cmd) Start() os.Error

Start starts the specified command but does not wait for it to complete.

func (*Cmd) StderrPipe

func (c *Cmd) StderrPipe() (io.Reader, os.Error)

StderrPipe returns a pipe that will be connected to the command's standard error when the command starts.

func (*Cmd) StdinPipe

func (c *Cmd) StdinPipe() (io.WriteCloser, os.Error)

StdinPipe returns a pipe that will be connected to the command's standard input when the command starts.

func (*Cmd) StdoutPipe

func (c *Cmd) StdoutPipe() (io.Reader, os.Error)

StdoutPipe returns a pipe that will be connected to the command's standard output when the command starts.

func (*Cmd) Wait

func (c *Cmd) Wait() os.Error

Wait waits for the command to exit. It must have been started by Start.

The returned error is nil if the command runs, has no problems copying stdin, stdout, and stderr, and exits with a zero exit status.

If the command fails to run or doesn't complete successfully, the error is of type *os.Waitmsg. Other error types may be returned for I/O problems.

type Error

type Error struct {
	Name  string
	Error os.Error
}

Error records the name of a binary that failed to be be executed and the reason it failed.

func (*Error) String

func (e *Error) String() string

Jump to

Keyboard shortcuts

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