Skip to content

Commit

Permalink
fix: print stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplan-michael committed Mar 21, 2024
1 parent 49bcc8f commit 108b9b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/config/fail/gobblefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ plays:
tasks:
- name: Fail on purpose
command:
cmd: echo "Simulated error message" >&2 && exit 1
cmd: echo "Simulated stdout message" >&1 && echo "Simulated stderr message" >&2 && exit 1
9 changes: 6 additions & 3 deletions pkg/utils/exec_utils/exec_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import (
)

func RawExec(password string, cmd string, args ...string) error {
var stderrBuf bytes.Buffer
var stderrBuf, stdoutBuf bytes.Buffer

c := exec.Command(cmd, args...)
if password != "" {
c.Stdin = bytes.NewBufferString(password + "\n")
}
c.Stderr = &stderrBuf
c.Stdout = &stdoutBuf
err := c.Run()

return fmt.Errorf("command failed: %v \nerror: %s", err, stderrBuf.String())
if err != nil {
return fmt.Errorf("command failed: %v \nmessage: %serror: %s", err, stdoutBuf.String(), stderrBuf.String())
}
return nil
}

func RawExecStdout(cmd string, args ...string) error {
Expand Down

0 comments on commit 108b9b2

Please # to comment.