Fix the err info of utils.ExecCmd

Signed-off-by: Haiyan Meng <haiyanalady@gmail.com>
This commit is contained in:
Haiyan Meng 2016-08-08 14:58:41 -04:00 committed by Mrunal Patel
parent f569f04154
commit e3a34aa26d

View file

@ -2,7 +2,9 @@ package utils
import ( import (
"bytes" "bytes"
"fmt"
"os/exec" "os/exec"
"strings"
"syscall" "syscall"
) )
@ -10,15 +12,17 @@ const PR_SET_CHILD_SUBREAPER = 36
func ExecCmd(name string, args ...string) (string, error) { func ExecCmd(name string, args ...string) (string, error) {
cmd := exec.Command(name, args...) cmd := exec.Command(name, args...)
var out bytes.Buffer var stdout bytes.Buffer
cmd.Stdout = &out var stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("`%v %v` failed: %v (%v)", name, strings.Join(args, " "), stderr.String(), err)
} }
return out.String(), nil return stdout.String(), nil
} }
// SetSubreaper sets the value i as the subreaper setting for the calling process // SetSubreaper sets the value i as the subreaper setting for the calling process