zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Go] go run 时 os.Getwd 和 os.Executable 获取程序根路径

2023-02-18 15:37:37 时间

os.Getwd返回的是当前路径

 os.Executable返回的是临时文件的绝对路径

package tools

import (
    "log"
    "os"
    "testing"
)

func TestOs(t *testing.T) {
    log.Println(os.Getwd())
    log.Println(os.Executable())
}