diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 845b737e28fc7..ecddee690de7c 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -374,6 +374,9 @@ func lookExtensions(path, dir string) (string, error) { // The Wait method will return the exit code and release associated resources // once the command exits. func (c *Cmd) Start() error { + if c.Path == "" && c.lookPathErr == nil { + c.lookPathErr = errors.New("exec: no command") + } if c.lookPathErr != nil { c.closeDescriptors(c.closeAfterStart) c.closeDescriptors(c.closeAfterWait) diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 73aa35f1aed1f..1913ae81c8976 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -1081,3 +1081,11 @@ func TestChildCriticalEnv(t *testing.T) { t.Error("no SYSTEMROOT found") } } + +func TestNoPath(t *testing.T) { + err := new(exec.Cmd).Start() + want := "exec: no command" + if err == nil || err.Error() != want { + t.Errorf("new(Cmd).Start() = %v, want %q", err, want) + } +}