Standard library / os
os.Executable()
Returns the executable pathname, which may no longer identify the same file if replaced. Symlink resolution varies by OS. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func Executable() (string, error)Return Value
(string, error)
Returns the executable pathname, which may no longer identify the same file if replaced.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "path/filepath")
func must(e error) { if e != nil { panic(e) }}func main() { p, e := os.Executable(); must(e); fmt.Println(filepath.IsAbs(p)) }