mirror of
https://github.com/go-task/task.git
synced 2026-06-30 16:14:19 +00:00
execext package: support context command
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package execext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
@@ -17,6 +18,6 @@ func init() {
|
||||
ShExists = err == nil
|
||||
}
|
||||
|
||||
func newShCommand(c string) *exec.Cmd {
|
||||
return exec.Command(ShPath, "-c", c)
|
||||
func newShCommand(ctx context.Context, c string) *exec.Cmd {
|
||||
return exec.CommandContext(ctx, ShPath, "-c", c)
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
package execext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// NewCommand returns a new command that runs on "sh" is available or on "cmd"
|
||||
// otherwise on Windows
|
||||
func NewCommand(c string) *exec.Cmd {
|
||||
return newShCommand(c)
|
||||
func NewCommand(ctx context.Context, c string) *exec.Cmd {
|
||||
return newShCommand(ctx, c)
|
||||
}
|
||||
|
||||
@@ -3,18 +3,19 @@
|
||||
package execext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// NewCommand returns a new command that runs on "sh" is available or on "cmd"
|
||||
// otherwise on Windows
|
||||
func NewCommand(c string) *exec.Cmd {
|
||||
func NewCommand(ctx context.Context, c string) *exec.Cmd {
|
||||
if ShExists {
|
||||
return newShCommand(c)
|
||||
return newShCommand(ctx, c)
|
||||
}
|
||||
return newCmdCommand(c)
|
||||
return newCmdCommand(ctx, c)
|
||||
}
|
||||
|
||||
func newCmdCommand(c string) *exec.Cmd {
|
||||
return exec.Command("cmd", "/C", c)
|
||||
func newCmdCommand(ctx context.Context, c string) *exec.Cmd {
|
||||
return exec.CommandContext(ctx, "cmd", "/C", c)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user