feature: Rudimentary "windows support"

This commit is contained in:
jamesread 2023-02-16 16:40:24 +00:00
parent 11bb3f129f
commit 9df61ab044
1 changed files with 10 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import (
"bytes" "bytes"
"context" "context"
"os/exec" "os/exec"
"runtime"
"time" "time"
) )
@ -162,6 +163,14 @@ func stepLogFinish(req *ExecutionRequest) bool {
return true return true
} }
func wrapCommandInShell(ctx context.Context, finalParsedCommand string) *exec.Cmd {
if runtime.GOOS == "windows" {
return exec.CommandContext(ctx, "cmd", "/C", finalParsedCommand)
}
return exec.CommandContext(ctx, "sh", "-c", finalParsedCommand)
}
func stepExec(req *ExecutionRequest) bool { func stepExec(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()
@ -169,7 +178,7 @@ func stepExec(req *ExecutionRequest) bool {
var stdout bytes.Buffer var stdout bytes.Buffer
var stderr bytes.Buffer var stderr bytes.Buffer
cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand) cmd := wrapCommandInShell(ctx, req.finalParsedCommand)
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr