Skip to content

Instantly share code, notes, and snippets.

@kumakichi
Created November 26, 2019 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumakichi/96299e45a2ae8d4c532a312c0cf35061 to your computer and use it in GitHub Desktop.
Save kumakichi/96299e45a2ae8d4c532a312c0cf35061 to your computer and use it in GitHub Desktop.
get running executable file real path in golang
package main
import (
"log"
"os"
"path/filepath"
)
func main() {
ex, err := os.Executable()
if err != nil {
log.Fatal(err)
}
realEx, err := filepath.EvalSymlinks(ex)
if err != nil {
log.Fatal(err)
}
dir := filepath.Dir(realEx)
if err != nil {
log.Fatal(err)
}
log.Println(dir)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment