]> Cypherpunks repositories - gostls13.git/commitdiff
exec: make LookPath work even when PATHEXT env variable is not set on Windows
authorAlex Brainman <alex.brainman@gmail.com>
Tue, 14 Jun 2011 15:46:05 +0000 (11:46 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 14 Jun 2011 15:46:05 +0000 (11:46 -0400)
R=golang-dev, mattn.jp
CC=golang-dev
https://golang.org/cl/4559062

src/pkg/exec/lp_windows.go

index 758861021453d350c912daf156e69838c484e5cb..1b3acc42bfa32b1e3b82e32b243d2a9ebb4d82af 100644 (file)
@@ -42,14 +42,19 @@ func findExecutable(file string, exts []string) (string, os.Error) {
 }
 
 func LookPath(file string) (f string, err os.Error) {
+       x := os.Getenv(`PATHEXT`)
+       if x == `` {
+               x = `.COM;.EXE;.BAT;.CMD`
+       }
        exts := []string{}
-       if x := os.Getenv(`PATHEXT`); x != `` {
-               exts = strings.Split(strings.ToLower(x), `;`, -1)
-               for i, e := range exts {
-                       if e == `` || e[0] != '.' {
-                               exts[i] = `.` + e
-                       }
+       for _, e := range strings.Split(strings.ToLower(x), `;`, -1) {
+               if e == "" {
+                       continue
+               }
+               if e[0] != '.' {
+                       e = "." + e
                }
+               exts = append(exts, e)
        }
        if strings.Contains(file, `\`) || strings.Contains(file, `/`) {
                if f, err = findExecutable(file, exts); err == nil {