jamesread 4 лет назад
Родитель
Сommit
5edeace62e
1 измененных файлов с 14 добавлено и 6 удалено
  1. 14 6
      internal/executor/executor.go

+ 14 - 6
internal/executor/executor.go

@@ -12,6 +12,7 @@ import (
 	"regexp"
 	"regexp"
 	"strings"
 	"strings"
 	"time"
 	"time"
+	"bytes"
 )
 )
 
 
 var (
 var (
@@ -190,20 +191,27 @@ func (e stepExec) Exec(req *ExecutionRequest) bool {
 	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.action.Timeout)*time.Second)
 	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.action.Timeout)*time.Second)
 	defer cancel()
 	defer cancel()
 
 
+	var stdout bytes.Buffer
+	var stderr bytes.Buffer
+
 	cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand)
 	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 {
 	if ctx.Err() == context.DeadlineExceeded {
 		req.logEntry.TimedOut = true
 		req.logEntry.TimedOut = true
 	}
 	}
 
 
-	req.logEntry.ExitCode = int32(cmd.ProcessState.ExitCode())
-	req.logEntry.Stdout = string(stdout)
-
 	return true
 	return true
 }
 }