mirror of
https://github.com/golang/go
synced 2024-11-21 18:04:40 -07:00
exec: missing docs, errors
R=rsc CC=golang-dev https://golang.org/cl/4550111
This commit is contained in:
parent
e59aa8ea4a
commit
f3c351982f
@ -63,6 +63,7 @@ type Cmd struct {
|
|||||||
|
|
||||||
err os.Error // last error (from LookPath, stdin, stdout, stderr)
|
err os.Error // last error (from LookPath, stdin, stdout, stderr)
|
||||||
process *os.Process
|
process *os.Process
|
||||||
|
finished bool // when Wait was called
|
||||||
childFiles []*os.File
|
childFiles []*os.File
|
||||||
closeAfterStart []*os.File
|
closeAfterStart []*os.File
|
||||||
closeAfterWait []*os.File
|
closeAfterWait []*os.File
|
||||||
@ -182,7 +183,7 @@ func (c *Cmd) writerDescriptor(w io.Writer) (f *os.File, err os.Error) {
|
|||||||
return pw, nil
|
return pw, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the specified command and waits for it to complete.
|
// Run starts the specified command and waits for it to complete.
|
||||||
//
|
//
|
||||||
// The returned error is nil if the command runs, has no problems
|
// The returned error is nil if the command runs, has no problems
|
||||||
// copying stdin, stdout, and stderr, and exits with a zero exit
|
// copying stdin, stdout, and stderr, and exits with a zero exit
|
||||||
@ -198,6 +199,7 @@ func (c *Cmd) Run() os.Error {
|
|||||||
return c.Wait()
|
return c.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start starts the specified command but does not wait for it to complete.
|
||||||
func (c *Cmd) Start() os.Error {
|
func (c *Cmd) Start() os.Error {
|
||||||
if c.err != nil {
|
if c.err != nil {
|
||||||
return c.err
|
return c.err
|
||||||
@ -239,10 +241,24 @@ func (c *Cmd) Start() os.Error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
func (c *Cmd) Wait() os.Error {
|
func (c *Cmd) Wait() os.Error {
|
||||||
if c.process == nil {
|
if c.process == nil {
|
||||||
return os.NewError("exec: not started")
|
return os.NewError("exec: not started")
|
||||||
}
|
}
|
||||||
|
if c.finished {
|
||||||
|
return os.NewError("exec: Wait was already called")
|
||||||
|
}
|
||||||
|
c.finished = true
|
||||||
msg, err := c.process.Wait(0)
|
msg, err := c.process.Wait(0)
|
||||||
|
|
||||||
var copyError os.Error
|
var copyError os.Error
|
||||||
@ -267,6 +283,9 @@ func (c *Cmd) Wait() os.Error {
|
|||||||
|
|
||||||
// Output runs the command and returns its standard output.
|
// Output runs the command and returns its standard output.
|
||||||
func (c *Cmd) Output() ([]byte, os.Error) {
|
func (c *Cmd) Output() ([]byte, os.Error) {
|
||||||
|
if c.Stdout != nil {
|
||||||
|
return nil, os.NewError("exec: Stdout already set")
|
||||||
|
}
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
c.Stdout = &b
|
c.Stdout = &b
|
||||||
err := c.Run()
|
err := c.Run()
|
||||||
@ -276,6 +295,12 @@ func (c *Cmd) Output() ([]byte, os.Error) {
|
|||||||
// CombinedOutput runs the command and returns its combined standard
|
// CombinedOutput runs the command and returns its combined standard
|
||||||
// output and standard error.
|
// output and standard error.
|
||||||
func (c *Cmd) CombinedOutput() ([]byte, os.Error) {
|
func (c *Cmd) CombinedOutput() ([]byte, os.Error) {
|
||||||
|
if c.Stdout != nil {
|
||||||
|
return nil, os.NewError("exec: Stdout already set")
|
||||||
|
}
|
||||||
|
if c.Stderr != nil {
|
||||||
|
return nil, os.NewError("exec: Stderr already set")
|
||||||
|
}
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
c.Stdout = &b
|
c.Stdout = &b
|
||||||
c.Stderr = &b
|
c.Stderr = &b
|
||||||
|
Loading…
Reference in New Issue
Block a user