From e8d0ea12cc8a98c0e003862e5e510d634ec49968 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Tue, 1 Mar 2022 22:14:55 -0400 Subject: [PATCH] fix: add substitute for exec syscall on windows --- api.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/api.go b/api.go index 3ca923d..cddd034 100644 --- a/api.go +++ b/api.go @@ -229,18 +229,27 @@ func appendPath(dir string) { func hlexec(L *lua.LState) int { cmd := L.CheckString(1) cmdArgs, _ := splitInput(cmd) - cmdPath, err := exec.LookPath(cmdArgs[0]) - if err != nil { - fmt.Println(err) - // if we get here, cmdPath will be nothing - // therefore nothing will run + if runtime.GOOS != "windows" { + cmdPath, err := exec.LookPath(cmdArgs[0]) + if err != nil { + fmt.Println(err) + // if we get here, cmdPath will be nothing + // therefore nothing will run + } + + // syscall.Exec requires an absolute path to a binary + // path, args, string slice of environments + syscall.Exec(cmdPath, cmdArgs, os.Environ()) + } else { + cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + cmd.Run() + os.Exit(0) } - // syscall.Exec requires an absolute path to a binary - // path, args, string slice of environments - // TODO: alternative for windows - syscall.Exec(cmdPath, cmdArgs, os.Environ()) - return 0 // random thought: does this ever return? + return 0 } // goro(fn)