Hi,

i notice a case where LookPath is not really looking for PATH.

I have a bin with some files along it, i need to get its path at runtime to 
find the other files.

I use a func like this, minus the fmt prints


func getBinPath() (string, error) {
  var err error
  wd := ""
    if filepath.Base(os.Args[0]) == "main" { // go run ...
        wd, err = os.Getwd()
    } else {
      bin, err := exec.LookPath(os.Args[0])
      if err == nil {
          wd = filepath.Dir(bin)
      }
    }
  fmt.Printf("%q\n", wd)
  fmt.Printf("%q\n", os.Args)
    return wd, err
}

When i run the command from a lambda dir, things are good,

C:\>go-msi generate-templates -h
"C:\\Program Files\\go-msi"
["go-msi" "generate-templates" "-h"]

Now the case where LookPath behaves unexpectedly occurs when i run the same 
from command, from a directory where a `go-msi.exe` file exists

C:\vagrant>go-msi generate-templates -h
"."
["go-msi" "generate-templates" "-h"]

It is unexpected in the sense that PATH does not contains '.' (C:\vagrant\ 
in that case).

Looks like LookPath is looking for '.' by itself.

C:\>echo %PATH%
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\MakeMsi\;
C:\Program Files (x86)\WiX Toolset v3.10\bin;
C:\Windows\system32;
C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\MakeMsi\;
C:\ProgramFiles (x86)\WiX Toolset v3.10\bin;
C:\wix310;
C:\Program Files\go-msi\


I guess if LookPath would search '.', after PATH, i would not have noticed 
this behavior.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to