Created
November 26, 2019 06:11
-
-
Save kumakichi/96299e45a2ae8d4c532a312c0cf35061 to your computer and use it in GitHub Desktop.
get running executable file real path in golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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