diff --git a/cli/exec.go b/cli/exec.go index 8d4577957..9681f1985 100644 --- a/cli/exec.go +++ b/cli/exec.go @@ -161,21 +161,34 @@ func ExecCommand(app *kingpin.Application, input ExecCommandInput) { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr + if err := cmd.Start(); err != nil { + app.Errorf("%v", err) + return + } + // wait for the command to finish + waitCh := make(chan error, 1) go func() { - sig := <-input.Signals - if cmd.Process != nil { - cmd.Process.Signal(sig) - } + waitCh <- cmd.Wait() + close(waitCh) }() - var waitStatus syscall.WaitStatus - if err := cmd.Run(); err != nil { - if exitError, ok := err.(*exec.ExitError); ok { - waitStatus = exitError.Sys().(syscall.WaitStatus) - os.Exit(waitStatus.ExitStatus()) - } - if err != nil { - app.Errorf("%v", err) + for { + select { + case sig := <-input.Signals: + if err = cmd.Process.Signal(sig); err != nil { + app.Errorf("%v", err) + break + } + case err := <-waitCh: + var waitStatus syscall.WaitStatus + if exitError, ok := err.(*exec.ExitError); ok { + waitStatus = exitError.Sys().(syscall.WaitStatus) + os.Exit(waitStatus.ExitStatus()) + } + if err != nil { + app.Errorf("%v", err) + return + } return } } diff --git a/cli/exec_test.go b/cli/exec_test.go index 8d395443e..36a842715 100644 --- a/cli/exec_test.go +++ b/cli/exec_test.go @@ -13,7 +13,7 @@ func ExampleExecCommand() { {Key: "llamas", Data: []byte(`{"AccessKeyID":"ABC","SecretAccessKey":"XYZ"}`)}, }) - app := kingpin.New(`aws-vault`, ``) + app := kingpin.New("aws-vault", "") ConfigureGlobals(app) ConfigureExecCommand(app) kingpin.MustParse(app.Parse([]string{