1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:34:42 -07:00

exec: make LookPath work even when PATHEXT env variable is not set on Windows

R=golang-dev, mattn.jp
CC=golang-dev
https://golang.org/cl/4559062
This commit is contained in:
Alex Brainman 2011-06-14 11:46:05 -04:00 committed by Russ Cox
parent 5af8e53a14
commit c195cc8d82

View File

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