1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package os 6 7 import "syscall" 8 9 var initCwd, initCwdErr = Getwd() 10 11 func executable() (string, error) { 12 path, err := syscall.Getexecname() 13 if err != nil { 14 return path, err 15 } 16 if len(path) > 0 && path[0] != '/' { 17 if initCwdErr != nil { 18 return path, initCwdErr 19 } 20 if len(path) > 2 && path[0:2] == "./" { 21 // skip "./" 22 path = path[2:] 23 } 24 return initCwd + "/" + path, nil 25 } 26 return path, nil 27 } 28