golang 读取运行程序的相关目录
获取运行程序的所在目录、工作目录
path D:\Workspaces\golang-demo23\mt76\build
os.Args D:\Workspaces\golang-demo23\mt76\build
Getwd D:\Workspaces\golang-demo23\mt76
./ D:\Workspaces\golang-demo23\mt76
import (
"fmt"
"os"
"path/filepath"
)
func main() {
fmt.Println("start m1")
path, _ := os.Executable()
fmt.Println("path", filepath.Dir(path))
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
fmt.Println("os.Args", dir)
dir, _ = os.Getwd()
fmt.Println("Getwd", dir)
dir, _ = filepath.Abs("./")
fmt.Println("./", dir)
}

浙公网安备 33010602011771号