Adding windows support for JobStart()

This commit is contained in:
Neko Box Coder 2025-03-14 11:17:17 +00:00
parent 96f2735075
commit 4658fa2888
No known key found for this signature in database
GPG Key ID: E33FCF170345E0F5
2 changed files with 10 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"io"
"os/exec"
"runtime"
)
var Jobs chan JobFunction
@ -54,7 +55,11 @@ func (f *CallbackFile) Write(data []byte) (int, error) {
// JobStart starts a shell command in the background with the given callbacks
// It returns an *exec.Cmd as the job id
func JobStart(cmd string, onStdout, onStderr, onExit func(string, []interface{}), userargs ...interface{}) *Job {
return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
if runtime.GOOS == "windows" {
return JobSpawn("cmd", []string{"/v:on", "/c", cmd}, onStdout, onStderr, onExit, userargs...)
} else {
return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
}
}
// JobSpawn starts a process with args in the background with the given callbacks

View File

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