summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-05-03 10:01:35 -0400
committerGopher Robot <gobot@golang.org>2022-05-03 16:29:56 +0000
commit61a585a32cc44cb1d8d00d12dcf101a61f145d69 (patch)
tree51ad5ccc50db805c3631d6e699644113bee73691
parente7508598bb8007ec2a04cb25a6076643af05c033 (diff)
downloadgo-git-61a585a32cc44cb1d8d00d12dcf101a61f145d69.tar.gz
os/exec: in Command, update cmd.Path even if LookPath returns an error
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>
-rw-r--r--src/os/exec/exec.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index dad63f13f9..042d7f465d 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -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
@@ -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
}