Skip to content

Commit f870350

Browse files
Adding windows support for JobStart()
1 parent da5d405 commit f870350

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
@@ -277,10 +277,10 @@ The packages and their contents are listed below (in Go type signatures):
277277
onExit func(string, []any), userargs ...any)
278278
*exec.Cmd`:
279279
Starts a background job by running the shell on the given command
280-
(using `sh -c`). Three callbacks can be provided which will be called
281-
when the command generates stdout, stderr, or exits. The userargs will
282-
be passed to the callbacks, along with the output as the first
283-
argument of the callback. Returns the started command.
280+
(using `sh -c` or `cmd /v:on /c`). Three callbacks can be provided which
281+
will be called when the command generates stdout, stderr, or exits.
282+
The userargs will be passed to the callbacks, along with the output
283+
as the first argument of the callback. Returns the started command.
284284

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

0 commit comments

Comments
 (0)