package main import ( "fmt" "log" "os" "os/exec" "path" "github.com/kardianos/osext" ) func main() { // Find location of executable with kardianos/osext exeFolder, err := osext.ExecutableFolder() if err != nil { log.Fatal(err) } // // These will require that the executable is in a directory within the $PATH // Find location of executable with Args[0] and exec.LookPath // Requires import of os, os/exec, and path argZero := os.Args[0] exePath, err := exec.LookPath(argZero) if err != nil { log.Fatal(err) } lookPath := path.Dir(exePath) // Output to comapre the results fmt.Printf("osext.ExeFolder : %s\n", exeFolder) fmt.Printf("exec.LookPath : %s\n", lookPath) }