feat: properly handle stdout when capturing plugn output

The previous output would also include a message like `exit status 1`. This allows us to silence that output and instead only capture that which was return from the subprocess.
This commit is contained in:
Jose Diaz-Gonzalez
2020-12-13 02:08:44 -05:00
parent ca2de6a4a3
commit b691c0affc

View File

@@ -2,6 +2,7 @@ package common
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@@ -79,7 +80,21 @@ func PlugnTrigger(triggerName string, args ...string) error {
// PlugnTriggerOutput fire the given plugn trigger with the given args // PlugnTriggerOutput fire the given plugn trigger with the given args
func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) { func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
return PlugnTriggerSetup(triggerName, args...).Output() rescueStderr := os.Stderr
r, w, _ := os.Pipe()
os.Stderr = w
out, err := PlugnTriggerSetup(triggerName, args...).Output()
w.Close()
readStderr, _ := ioutil.ReadAll(r)
os.Stderr = rescueStderr
var stderr error
if err != nil {
stderr = fmt.Errorf(string(readStderr[:]))
}
return out, stderr
} }
// PlugnTriggerSetup sets up a plugn trigger call // PlugnTriggerSetup sets up a plugn trigger call