2024-07-19 13:48:01 +00:00
|
|
|
//go:build windows
|
2022-03-16 23:44:32 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"os"
|
2022-05-22 00:53:36 +00:00
|
|
|
"syscall"
|
2022-03-16 23:44:32 +00:00
|
|
|
)
|
|
|
|
|
2022-05-22 00:53:36 +00:00
|
|
|
var bgProcAttr *syscall.SysProcAttr = &syscall.SysProcAttr{
|
|
|
|
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
|
|
|
|
}
|
|
|
|
|
2022-03-18 00:22:30 +00:00
|
|
|
func findExecutable(path string, inPath, dirs bool) error {
|
2022-03-16 23:44:32 +00:00
|
|
|
nameExt := filepath.Ext(path)
|
2022-03-18 00:22:30 +00:00
|
|
|
pathExts := filepath.SplitList(os.Getenv("PATHEXT"))
|
|
|
|
if inPath {
|
|
|
|
if nameExt == "" {
|
|
|
|
for _, ext := range pathExts {
|
|
|
|
_, err := os.Stat(path + ext)
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_, err := os.Stat(path)
|
2022-03-16 23:44:32 +00:00
|
|
|
if err == nil {
|
2022-03-18 00:22:30 +00:00
|
|
|
if contains(pathExts, nameExt) { return nil }
|
|
|
|
return errNotExec
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 00:22:30 +00:00
|
|
|
} else {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err == nil {
|
|
|
|
if contains(pathExts, nameExt) { return nil }
|
|
|
|
return errNotExec
|
|
|
|
}
|
2022-03-16 23:44:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return os.ErrNotExist
|
|
|
|
}
|