Go Home Page
The Go Programming Language

Package exec

import "exec"

The exec package runs external commands.

Package files

exec.go

Constants

Arguments to Run.

const (
    DevNull = iota
    PassThrough
    Pipe
    MergeWithStdout
)

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.

TODO(rsc): Does LookPath belong in os instead?

type Cmd

A Cmd represents a running command. Stdin, Stdout, and Stderr are Files representing pipes connected to the running command's standard input, output, and error, or else nil, depending on the arguments to Run. Pid is the running command's operating system process ID.

type Cmd struct {
    Stdin  *os.File
    Stdout *os.File
    Stderr *os.File
    Pid    int
}

func Run

func Run(argv0 string, argv, envv []string, dir string, stdin, stdout, stderr int) (p *Cmd, err os.Error)

Run starts the binary prog running with arguments argv and environment envv. It returns a pointer to a new Cmd representing the command or an error.

The parameters stdin, stdout, and stderr specify how to handle standard input, output, and error. The choices are DevNull (connect to /dev/null), PassThrough (connect to the current process's standard stream), Pipe (connect to an operating system pipe), and MergeWithStdout (only for standard error; use the same file descriptor as was used for standard output). If a parameter is Pipe, then the corresponding field (Stdin, Stdout, Stderr) of the returned Cmd is the other end of the pipe. Otherwise the field in Cmd is nil.

func (*Cmd) Close

func (p *Cmd) Close() os.Error

Close waits for the running command p to exit, if it hasn't already, and then closes the non-nil file descriptors p.Stdin, p.Stdout, and p.Stderr.

func (*Cmd) Wait

func (p *Cmd) Wait(options int) (*os.Waitmsg, os.Error)

Wait waits for the running command p, returning the Waitmsg returned by os.Wait and an error. The options are passed through to os.Wait. Setting options to 0 waits for p to exit; other options cause Wait to return for other process events; see package os for details.