From 41e9485057da398a98d1c34b70d27ffe4e172b98 Mon Sep 17 00:00:00 2001 From: Chris Mague Date: Wed, 26 Sep 2018 09:32:21 -0700 Subject: [PATCH] use combined output --- plugin.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/plugin.go b/plugin.go index fcdaf3f..a4ab5a3 100644 --- a/plugin.go +++ b/plugin.go @@ -1,9 +1,7 @@ package main import ( - "bufio" "fmt" - "io" "io/ioutil" "os" "os/exec" @@ -179,27 +177,20 @@ func (p Plugin) Exec() error { }).Fatal("Failed to execute a command") } } else { - // open the out file for writing - outfile, err := os.Create(c.Ofile) - if err != nil { - panic(err) - } - defer outfile.Close() + logrus.WithFields(logrus.Fields{ + "file": c.Ofile, + "command": strings.Join(c.Tfcmd.Args, " "), + }).Info("Command") - stdoutPipe, err := c.Tfcmd.StdoutPipe() + out, err := c.Tfcmd.CombinedOutput() if err != nil { - panic(err) - } - - writer := bufio.NewWriter(outfile) - - err = c.Tfcmd.Start() - if err != nil { - panic(err) + logrus.WithFields(logrus.Fields{ + "command": strings.Join(c.Tfcmd.Args, " "), + "error": err, + }).Fatal("Failed to execute a command") } - - go io.Copy(writer, stdoutPipe) - c.Tfcmd.Wait() + f, _ := os.Create(c.Ofile) + f.Write(out) } }