diff options
Diffstat (limited to 'misc/dashboard/builder/exec.go')
-rw-r--r-- | misc/dashboard/builder/exec.go | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/misc/dashboard/builder/exec.go b/misc/dashboard/builder/exec.go index a7ef93308..0db509136 100644 --- a/misc/dashboard/builder/exec.go +++ b/misc/dashboard/builder/exec.go @@ -19,16 +19,11 @@ func run(envv []string, dir string, argv ...string) os.Error { log.Println("run", argv) } argv = useBash(argv) - bin, err := 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() + cmd := exec.Command(argv[0], argv[1:]...) + cmd.Dir = dir + cmd.Env = envv + cmd.Stderr = os.Stderr + return cmd.Run() } // runLog runs a process and returns the combined stdout/stderr, @@ -38,16 +33,7 @@ func runLog(envv []string, logfile, dir string, argv ...string) (output string, log.Println("runLog", argv) } argv = useBash(argv) - bin, err := 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) var w io.Writer = b if logfile != "" { @@ -58,23 +44,22 @@ func runLog(envv []string, logfile, dir string, argv ...string) (output string, defer f.Close() w = io.MultiWriter(f, b) } - _, err = io.Copy(w, p.Stdout) - if err != nil { - return - } - wait, err := p.Wait(0) + + cmd := exec.Command(argv[0], argv[1:]...) + cmd.Dir = dir + cmd.Env = envv + cmd.Stdout = w + cmd.Stderr = w + + err = cmd.Run() + output = b.String() if err != nil { + if ws, ok := err.(*os.Waitmsg); ok { + exitStatus = ws.ExitStatus() + } return } - return b.String(), wait.WaitStatus.ExitStatus(), nil -} - -// lookPath looks for cmd in $PATH if cmd does not begin with / or ./ or ../. -func lookPath(cmd string) (string, os.Error) { - if strings.HasPrefix(cmd, "/") || strings.HasPrefix(cmd, "./") || strings.HasPrefix(cmd, "../") { - return cmd, nil - } - return exec.LookPath(cmd) + return } // useBash prefixes a list of args with 'bash' if the first argument |