Skip to content

Commit

Permalink
bugfix: Working stderr!
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesread committed Jan 5, 2022
1 parent 07ca9f2 commit 5edeace
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"regexp"
"strings"
"time"
"bytes"
)

var (
Expand Down Expand Up @@ -190,20 +191,27 @@ func (e stepExec) Exec(req *ExecutionRequest) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.action.Timeout)*time.Second)
defer cancel()

var stdout bytes.Buffer
var stderr bytes.Buffer

cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand)
stdout, stderr := cmd.Output()
cmd.Stdout = &stdout
cmd.Stderr = &stderr

runerr := cmd.Run()

req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode())
req.logEntry.Stdout = stdout.String()
req.logEntry.Stderr = stderr.String()

if stderr != nil {
req.logEntry.Stderr = stderr.Error()
if runerr != nil {
req.logEntry.Stderr = runerr.Error() + "\n\n" + req.logEntry.Stderr
}

if ctx.Err() == context.DeadlineExceeded {
req.logEntry.TimedOut = true
}

req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode())
req.logEntry.Stdout = string(stdout)

return true
}

Expand Down

0 comments on commit 5edeace

Please sign in to comment.