Find the path to the executable

You can use os.Executable for getting executable path on Go 1.8 or above version.

import (
    "os"
    "path"
    "log"
)

func main() {
    ex, err := os.Executable()
    if err != nil { log.Fatal(err) }
    dir := path.Dir(ex)
    log.Print(dir)
}

Leave a Comment