Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'g update'自我更新 #19

Closed
voidint opened this issue Jun 16, 2019 · 5 comments
Closed

'g update'自我更新 #19

voidint opened this issue Jun 16, 2019 · 5 comments

Comments

@voidint
Copy link
Owner

voidint commented Jun 16, 2019

如何获取当前可执行程序的绝对路径?

  • Linux: os.Readlink("/proc/self/exe")
  • exec.LookPath("g")方式可能并不准确,因为依赖于PATH环境变量。
@Zachary-Zhao
Copy link

filepath.Abs(os.Args[0])

@voidint
Copy link
Owner Author

voidint commented Mar 26, 2020

filepath.Abs(os.Args[0])

这个函数是不能满足需求的哦。可以具体看下函数的实现:如果入参不是绝对路径(如filepath.Abs("bash")),返回的是${当前工作目录}/bash

@HaoKunT
Copy link
Contributor

HaoKunT commented May 5, 2020

试试这个包?

go-update

@Zerorigin
Copy link

Zerorigin commented Feb 13, 2022

import (
    "log"
    "os"
    "path/filepath"
)
// 获取执行程序时程序所在目录 - 适用于 go run/build
if execPath, err = os.Executable(); err != nil {
    log.Println(err)
}
execPath, _ = filepath.EvalSymlinks(filepath.Dir(execPath))

代码片段参考:https://zhuanlan.zhihu.com/p/363714760

@voidint
Copy link
Owner Author

voidint commented Apr 3, 2022

1.3.0 版本已支持g update命令,此issue关闭。

@voidint voidint closed this as completed Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants