@@ -333,9 +333,9 @@ type Cmd struct {
333
333
// and https://go.dev/issue/43724 for more context.
334
334
lookPathErr error
335
335
336
- // calledLookExtensions indicates whether
337
- // lookExtensions has been called in Cmd.Command .
338
- calledLookExtensions bool
336
+ // cacheLookExtensions cache the result of calling lookExtensions,
337
+ // use it only on windows .
338
+ cacheLookExtensions string
339
339
}
340
340
341
341
// A ctxResult reports the result of watching the Context associated with a
@@ -440,11 +440,8 @@ func Command(name string, arg ...string) *Cmd {
440
440
// Note that we cannot add an extension here for relative paths, because
441
441
// cmd.Dir may be set after we return from this function and that may cause
442
442
// the command to resolve to a different extension.
443
- cmd .calledLookExtensions = true
444
443
lp , err := lookExtensions (name , "" )
445
- if lp != "" {
446
- cmd .Path = lp
447
- }
444
+ cmd .cacheLookExtensions = lp
448
445
if err != nil {
449
446
cmd .Err = err
450
447
}
@@ -646,7 +643,10 @@ func (c *Cmd) Start() error {
646
643
return c .Err
647
644
}
648
645
lp := c .Path
649
- if runtime .GOOS == "windows" && ! c .calledLookExtensions {
646
+ if c .cacheLookExtensions == "" {
647
+ lp = c .cacheLookExtensions
648
+ }
649
+ if runtime .GOOS == "windows" && c .cacheLookExtensions == "" {
650
650
// If c.Path is relative, we had to wait until now
651
651
// to resolve it in case c.Dir was changed.
652
652
// (If it is absolute, we already resolved its extension in Command
0 commit comments