|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"path" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/kardianos/osext" |
|
|
|
) |
|
|
@ -29,7 +30,22 @@ func main() { |
|
|
|
} |
|
|
|
lookPath := path.Dir(exePath) |
|
|
|
|
|
|
|
// Walk the path environment locally
|
|
|
|
walkPath := pathWalker(os.Args[0]) |
|
|
|
|
|
|
|
// Output to comapre the results
|
|
|
|
fmt.Printf("osext.ExeFolder : %s\n", exeFolder) |
|
|
|
fmt.Printf("exec.LookPath : %s\n", lookPath) |
|
|
|
fmt.Printf("local walkPath : %s\n", walkPath) |
|
|
|
} |
|
|
|
|
|
|
|
func pathWalker(file string) string { |
|
|
|
path := os.Getenv("PATH") |
|
|
|
for _, dir := range strings.Split(path, ":") { |
|
|
|
exe := dir + "/" + file |
|
|
|
if _, err := os.Stat(exe); err == nil { |
|
|
|
return dir |
|
|
|
} |
|
|
|
} |
|
|
|
return "not found" |
|
|
|
} |