1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

fix: More compatible behavior for getting the current executable dir

This commit is contained in:
Madray Haven 2022-09-11 19:58:36 +08:00
parent 8389d9195d
commit 532f55fba0
2 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -5,6 +5,7 @@ package server
import (
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
@ -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)