Browse Source

use combined output

pull/78/head
Chris Mague 6 years ago
parent
commit
41e9485057
  1. 31
      plugin.go

31
plugin.go

@ -1,9 +1,7 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
@ -179,27 +177,20 @@ func (p Plugin) Exec() error {
}).Fatal("Failed to execute a command") }).Fatal("Failed to execute a command")
} }
} else { } else {
// open the out file for writing logrus.WithFields(logrus.Fields{
outfile, err := os.Create(c.Ofile) "file": c.Ofile,
if err != nil { "command": strings.Join(c.Tfcmd.Args, " "),
panic(err) }).Info("Command")
}
defer outfile.Close()
stdoutPipe, err := c.Tfcmd.StdoutPipe()
if err != nil {
panic(err)
}
writer := bufio.NewWriter(outfile)
err = c.Tfcmd.Start() out, err := c.Tfcmd.CombinedOutput()
if err != nil { if err != nil {
panic(err) logrus.WithFields(logrus.Fields{
"command": strings.Join(c.Tfcmd.Args, " "),
"error": err,
}).Fatal("Failed to execute a command")
} }
f, _ := os.Create(c.Ofile)
go io.Copy(writer, stdoutPipe) f.Write(out)
c.Tfcmd.Wait()
} }
} }

Loading…
Cancel
Save