dongxilan9351
2017-10-04 17:11
浏览 345
已采纳

执行“ go run file.go”命令后,可执行文件存储在哪里?

Where does go compiler store the executable file after executing following command?

$> go run file.go
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwen7283 2017-10-04 17:15
    已采纳

    In the /tmp folder, if you're using unix machine.

    In the \Users\SomeUser\AppData\Local\Temp\ if you're on windows.

    点赞 打赏 评论
  • doumi2106 2017-10-06 23:37

    In Go 1.8 or later, use os.Executable to see where your executable is located:

    exePath, err := os.Executable()
    if err != nil {
        fmt.Println("Failed to get executable path:", err)
    } else {
        fmt.Println("Executable:", exePath)
    }
    

    go run myprog.go

    Executable: /tmp/go-build260998498/command-line-arguments/_obj/exe/myprog

    点赞 打赏 评论