Skip to content

Commit 54d117b

Browse files
Adding windows support for JobStart()
1 parent 86e19af commit 54d117b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

internal/shell/job.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"io"
66
"os/exec"
7+
"runtime"
78
)
89

910
var Jobs chan JobFunction
@@ -54,7 +55,11 @@ func (f *CallbackFile) Write(data []byte) (int, error) {
5455
// JobStart starts a shell command in the background with the given callbacks
5556
// It returns an *exec.Cmd as the job id
5657
func JobStart(cmd string, onStdout, onStderr, onExit func(string, []any), userargs ...any) *Job {
57-
return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
58+
if runtime.GOOS == "windows" {
59+
return JobSpawn("cmd", []string{"/v:on", "/c", cmd}, onStdout, onStderr, onExit, userargs...)
60+
} else {
61+
return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
62+
}
5863
}
5964

6065
// JobSpawn starts a process with args in the background with the given callbacks

runtime/help/plugins.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ The packages and their contents are listed below (in Go type signatures):
278278
onExit func(string, []any), userargs ...any)
279279
*exec.Cmd`:
280280
Starts a background job by running the shell on the given command
281-
(using `sh -c`). Three callbacks can be provided which will be called
282-
when the command generates stdout, stderr, or exits. The userargs will
283-
be passed to the callbacks, along with the output as the first
284-
argument of the callback. Returns the started command.
281+
(using `sh -c` or `cmd /v:on /c`). Three callbacks can be provided which
282+
will be called when the command generates stdout, stderr, or exits.
283+
The userargs will be passed to the callbacks, along with the output
284+
as the first argument of the callback. Returns the started command.
285285

286286
- `JobSpawn(cmd string, cmdArgs []string, onStdout, onStderr,
287287
onExit func(string, []any), userargs ...any)

0 commit comments

Comments
 (0)