mirror of
https://github.com/golang/go
synced 2024-11-17 14:04:48 -07:00
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>
This commit is contained in:
parent
e7508598bb
commit
61a585a32c
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user