Procházet zdrojové kódy

Merge pull request #32 from OliveTin/exec-without-shell

bugfix: Working stderr!
James Read před 4 roky
rodič
revize
c263a84aa7
2 změnil soubory, kde provedl 15 přidání a 7 odebrání
  1. 14 6
      internal/executor/executor.go
  2. 1 1
      webui/js/ActionButton.js

+ 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
 }
 }
 
 

+ 1 - 1
webui/js/ActionButton.js

@@ -15,7 +15,7 @@ class ActionButton extends window.HTMLElement {
     this.updateFromJson(json)
     this.updateFromJson(json)
 
 
     // DOM Attributes
     // DOM Attributes
-    this.setAttribute("role", "none")
+    this.setAttribute('role', 'none')
     this.btn.title = json.title
     this.btn.title = json.title
     this.btn.onclick = () => {
     this.btn.onclick = () => {
       console.log(json.arguments)
       console.log(json.arguments)