mirror of
https://github.com/golang/go
synced 2024-11-19 11:44:45 -07:00
3e8cc7f114
R=rsc CC=golang-dev https://golang.org/cl/2126042
46 lines
927 B
Go
46 lines
927 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"exec"
|
|
"os"
|
|
)
|
|
|
|
// run is a simple wrapper for exec.Run/Close
|
|
func run(envv []string, dir string, argv ...string) os.Error {
|
|
bin, err := exec.LookPath(argv[0])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
p, err := exec.Run(bin, argv, envv, dir,
|
|
exec.DevNull, exec.DevNull, exec.PassThrough)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return p.Close()
|
|
}
|
|
|
|
// runLog runs a process and returns the combined stdout/stderr
|
|
func runLog(envv []string, dir string, argv ...string) (output string, exitStatus int, err os.Error) {
|
|
bin, err := exec.LookPath(argv[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
p, err := exec.Run(bin, argv, envv, dir,
|
|
exec.DevNull, exec.Pipe, exec.MergeWithStdout)
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer p.Close()
|
|
b := new(bytes.Buffer)
|
|
_, err = b.ReadFrom(p.Stdout)
|
|
if err != nil {
|
|
return
|
|
}
|
|
w, err := p.Wait(0)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return b.String(), w.WaitStatus.ExitStatus(), nil
|
|
}
|