diff --git a/execext/exec.go b/execext/exec.go index b751da34..86328f55 100644 --- a/execext/exec.go +++ b/execext/exec.go @@ -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) } diff --git a/execext/exec_other.go b/execext/exec_other.go index e8f5410d..5f36715c 100644 --- a/execext/exec_other.go +++ b/execext/exec_other.go @@ -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) } diff --git a/execext/exec_win.go b/execext/exec_win.go index 885fff8b..64ec3194 100644 --- a/execext/exec_win.go +++ b/execext/exec_win.go @@ -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) } diff --git a/task.go b/task.go index 73e4dbf6..ee94d2df 100644 --- a/task.go +++ b/task.go @@ -1,6 +1,7 @@ package task import ( + "context" "fmt" "log" "os" @@ -189,7 +190,7 @@ func (t *Task) runCommand(i int) error { if err != nil { return err } - cmd := execext.NewCommand(c) + cmd := execext.NewCommand(context.Background(), c) if dir != "" { cmd.Dir = dir } diff --git a/variable_handling.go b/variable_handling.go index ca075ba5..855b80b0 100644 --- a/variable_handling.go +++ b/variable_handling.go @@ -2,6 +2,7 @@ package task import ( "bytes" + "context" "encoding/json" "errors" "io/ioutil" @@ -32,7 +33,7 @@ func handleDynamicVariableContent(value string) (string, error) { if result, ok := varCmds[value]; ok { return result, nil } - cmd := execext.NewCommand(value[1:]) + cmd := execext.NewCommand(context.Background(), value[1:]) cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr b, err := cmd.Output()