Skip to content

Commit

Permalink
fix: More compatible behavior for getting the current executable dir
Browse files Browse the repository at this point in the history
  • Loading branch information
sgpublic committed Sep 11, 2022
1 parent 8389d91 commit 532f55f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ func ResetWorkingDir() {
args = append(args, os.Args[i])
}
}
p, _ := filepath.Abs(os.Args[0])
ex, _ := os.Executable()
p, _ := filepath.Abs(ex)
_, err := os.Stat(p)
if !(err == nil || errors.Is(err, os.ErrExist)) {
log.Fatalf("重置工作目录时出现错误: 无法找到路径 %v", p)
Expand Down
5 changes: 4 additions & 1 deletion server/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package server
import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"

Expand All @@ -28,7 +29,9 @@ func Daemon() {
execArgs = append(execArgs, args[i])
}

proc := exec.Command(os.Args[0], execArgs...)
ex, _ := os.Executable()
p, _ := filepath.Abs(ex)
proc := exec.Command(p, execArgs...)
err := proc.Start()
if err != nil {
panic(err)
Expand Down

0 comments on commit 532f55f

Please sign in to comment.