Hilbish/execfile_windows.go

43 lines
782 B
Go
Raw Permalink Normal View History

2024-07-19 13:48:01 +00:00
//go:build windows
package main
import (
"path/filepath"
"os"
"syscall"
)
var bgProcAttr *syscall.SysProcAttr = &syscall.SysProcAttr{
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
func findExecutable(path string, inPath, dirs bool) error {
nameExt := filepath.Ext(path)
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)
if err == nil {
if contains(pathExts, nameExt) { return nil }
return errNotExec
}
}
} else {
_, err := os.Stat(path)
if err == nil {
if contains(pathExts, nameExt) { return nil }
return errNotExec
}
}
return os.ErrNotExist
}