// NewExec
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
)
func main() {
execPath, err := exec.LookPath(os.Args[0])
if err != nil {
log.Fatal(err)
}
// Is Symlink
fi, err := os.Lstat(execPath)
if err != nil {
log.Fatal(err)
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
execPath, err = os.Readlink(execPath)
if err != nil {
log.Fatal(err)
}
}
execDir := filepath.Dir(execPath)
if execDir == "." {
execDir, err = os.Getwd()
if err != nil {
log.Fatal(err)
}
}
fmt.Print(execDir)
cmd := exec.Command(execDir + "/XML.exe")
err = cmd.Run()
if err != nil {
fmt.Println(err)
}
cmd = exec.Command(execDir + "/MOW.exe")
err = cmd.Run()
if err != nil {
fmt.Println(err)
}
}
go语言获取exe文件执行路径
最新推荐文章于 2024-09-14 14:20:12 发布