1
votes

I have written a AutoHotkey script that works well uncompiled, but no matter which Base File (.bin) I use to compile the exe in Ahk2Exe, it fails for some unknown reason. Here's the AHK script:

SetTitleMatchMode, 2
WinGet, PID, PID, Anime Studio ahk_class LM_Wnd
Process, Close, %PID%
if 1 && (%ErrorLevel% != 0)
{
Run, %1%
}

And here's how I'm running it, from a Lua script (double-quotes are for spaces in actual paths):

--to uncompiled AHK (working code)
os.execute("C:/Users/JWesley/Desktop/AutoHotkey/AutoHotkeyU64.exe ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS.ahk".."\"".." "..path)
--to compiled AHK (not working)
os.execute("\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path)

I'm passing the variable "path" from Lua to the AHK script (%1%). I've tried setting the AHK compiled exe to Run As Administrator, but that didn't help.

path = "C:/Users/JWesley/Desktop/test.anime"

I've tried using os.execute('pause') so that I have a chance to read any command prompt messages, but the first one still closes before the paused one opens. EDIT: Okay, I got this to leave the prompt open:

os.execute("cmd.exe /k"..'"C:\\Users\\JWesley\\Desktop\\AutoHotkey\\AutoHotkeyU64.exe" "C:\\Users\\JWesley\\Files\\AS\\Anime Studio Pro\\scripts\\utility\\ReopenAS.ahk" "' .. path .. '"')

And got this message in the prompt:

The filename, directory name, or volume label syntax is incorrect.
1
How does the exe fail? Does is fail to run at all? Or does it run with unexpected results? If it does run, what are the contents of the command line parameters? I don't know lua, maybe it would help if you displayed the parameters you pass in a more general syntax. Did you take the difference between compiled and uncompiled scripts into account?MCL
What is path? Is it relative? Maybe the problem is that the executable file is in a different directory (uncompiled: C:\AutoHotkey, compiled: C:\ )?CherryDT
A string declared using 's doesn't need to escape "s.user6245072
@MCL The command prompt appears, but closes before I can read any error messages. I'll look into what it will take to have either AHK or Lua return these. Or maybe there's a command line switch to keep the prompt open? Yes, I showed the paths, from Lua, that call the uncompiled and compiled versions of the AHK script.J. Wesley
@CherryDT Path is absolute. The AHK executable is supposed to include the interpreter, etc., so not need for the compiled script to access that.J. Wesley

1 Answers

0
votes

I found a solution here: os.execute with filename and argument containing spaces Turns out it was more a Lua problem than AutoHotkey, although I'm still unsure why the difference between compiled and uncompiled AHK script. In Lua, I checked if the path had any spaces, and if so:

path = "\""..path.."\""

Then I did:

com = "\"".."type NUL && ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path.."\""
os.execute(com)

Supposedly this keeps the command line from removing the outer quotes, which are necessary with spaces in the path.

Now my only problem is the compiled script running slow due to my anti-virus, but that's a separate issue.

Thanks for the feedback.