AHK V2: Any way to catch "Script file not found" when using Run command?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

AHK V2: Any way to catch "Script file not found" when using Run command?

23 Jun 2018, 19:07

I find that the following code will catch an OS error (i.e. one that returns non-zero to A_LastError):

Code: Select all

AppExe := '"AutoHotkeyU64.exe" "NonExistingScript.ahk"'
		
try
    Run AppExe
catch
	MsgBox('Can`'t Run "' AppExe '".')
But if the OS can launch ahk and ahk can't find the script, it's not the OS that returns an error, it's AHK -- so catch doesn't er... catch it. And ErrorLevel returns 0. I'm not seeing any way to "catch" this error.

Only thing I can think of is to do a FileExist(scriptfile) before the run command. Any other options?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: AHK V2: Any way to catch "Script file not found" when using Run command?

23 Jun 2018, 22:06

No. You'll have to check that the file exists before attempting to run it.

Run and RunWait in v2 do not set ErrorLevel. It is 0 only if it was 0 before calling the function.

Run in v1 sets ErrorLevel if you use the UseErrorLevel option, but ErrorLevel is "ERROR" only when an exception would have been thrown.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Archimede, songdg and 35 guests