From 0877a6a18c89d7e495e4cdc41daa31df31127717 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Sat, 15 Dec 2018 02:37:39 +0000 Subject: [PATCH] Print out stderr if run command finish with error Signed-off-by: Leo Chen --- utils/utils.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/utils.go b/utils/utils.go index 1c5f45b44..9c910a485 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -44,6 +44,8 @@ func GetUniqueIDFromIPPort(ip, port string) uint16 { // RunCmd runs command `name` with arguments `args` func RunCmd(name string, args ...string) error { cmd := exec.Command(name, args...) + stderrBytes := &bytes.Buffer{} + cmd.Stderr = stderrBytes if err := cmd.Start(); err != nil { log.Fatal(err) return err @@ -53,6 +55,7 @@ func RunCmd(name string, args ...string) error { go func() { if err := cmd.Wait(); err != nil { log.Printf("Command finished with error: %v", err) + log.Printf("Stderr: %v", string(stderrBytes.Bytes())) } else { log.Printf("Command finished successfully") }