فهرست منبع

feature: Rudimentary "windows support"

jamesread 3 سال پیش
والد
کامیت
9df61ab044
1فایلهای تغییر یافته به همراه10 افزوده شده و 1 حذف شده
  1. 10 1
      internal/executor/executor.go

+ 10 - 1
internal/executor/executor.go

@@ -9,6 +9,7 @@ import (
 	"bytes"
 	"context"
 	"os/exec"
+	"runtime"
 	"time"
 )
 
@@ -162,6 +163,14 @@ func stepLogFinish(req *ExecutionRequest) bool {
 	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 {
 	ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.action.Timeout)*time.Second)
 	defer cancel()
@@ -169,7 +178,7 @@ func stepExec(req *ExecutionRequest) bool {
 	var stdout bytes.Buffer
 	var stderr bytes.Buffer
 
-	cmd := exec.CommandContext(ctx, "sh", "-c", req.finalParsedCommand)
+	cmd := wrapCommandInShell(ctx, req.finalParsedCommand)
 	cmd.Stdout = &stdout
 	cmd.Stderr = &stderr