Skip to content

Commit

Permalink
os/exec: in Command, update cmd.Path even if LookPath returns an error
Browse files Browse the repository at this point in the history
Fixes #52666.
Updates #43724.
Updates #43947.

Change-Id: I72cb585036b7e93cd7adbff318b400586ea97bd5
Reviewed-on: https://go-review.googlesource.com/c/go/+/403694
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed May 3, 2022
1 parent e750859 commit 61a585a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/os/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// They may not run on Windows, and they do not run in the Go Playground
// used by golang.org and godoc.org.
//
// Executables in the current directory
// # Executables in the current directory
//
// The functions Command and LookPath look for a program
// in the directories listed in the current path, following the
Expand Down Expand Up @@ -256,11 +256,16 @@ func Command(name string, arg ...string) *Cmd {
Args: append([]string{name}, arg...),
}
if filepath.Base(name) == name {
if lp, err := LookPath(name); err != nil {
cmd.Err = err
} else {
lp, err := LookPath(name)
if lp != "" {
// Update cmd.Path even if err is non-nil.
// If err is ErrDot (especially on Windows), lp may include a resolved
// extension (like .exe or .bat) that should be preserved.
cmd.Path = lp
}
if err != nil {
cmd.Err = err
}
}
return cmd
}
Expand Down

0 comments on commit 61a585a

Please sign in to comment.