Skip to content

Commit 4658fa2

Browse files
Adding windows support for JobStart()
1 parent 96f2735 commit 4658fa2

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

283283
- `JobSpawn(cmd string, cmdArgs []string, onStdout, onStderr,
284284
onExit func(string, []interface{}), userargs ...interface{})

0 commit comments

Comments
 (0)