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

bugfix: Working stderr!
This commit is contained in:
James Read 2022-01-05 10:53:40 +00:00 committed by GitHub
commit c263a84aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -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()
cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand) var stdout bytes.Buffer
stdout, stderr := cmd.Output() var stderr bytes.Buffer
if stderr != nil { cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand)
req.logEntry.Stderr = stderr.Error() 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 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
} }

View File

@ -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)