I asked this on stack overflow and got this answer:

// Shortcut to get the path to the current executable
func ExecPath() string {
var here = os.Args[0]
Log("Raw path: %s", here)
here, err := filepath.Abs(here)
Log("Abs path: %s", here)
if err != nil {
Log("ExecPath: Weird path: %s\n", err)
here = path.Dir(here)
Log("Exec path: %s", here)
return here

However, this fails and returns '.' on windows. Looking into it, it's
because Args[0] is in c:\fsdf\sdfdsf\sdf format, which filepath.Abs() and
path.Dir() don't seem to parse.

ie. Output on windows:
Raw path: c:\projects\go\worker\worker.exe
Abs path: c:\projects\go\worker\worker.exe
Exec path: .

Is this a bug in filepath.Abs() ? Surely abs should either error or produce
output which is correctly formatted? (ie. C:/project/go/worker/worker.exe)


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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 4 | next ›
Discussion Overview
groupgolang-nuts @
postedApr 20, '13 at 5:46a
activeApr 20, '13 at 2:41p



site design / logo © 2021 Grokbase