To return the exit code, you want to call ExitApp along with your desired code. Use IfExist to determine if a file exists. This means that the script you are calling should look like this:
IfExist, c:\test.txt ExitApp, 1 Else ExitApp 0
When calling the script, you must use RunWait and pass the UseErrorLevel
parameter to UseErrorLevel
. This will set the ErrorLevel
variable to the exit code of the called process if it starts correctly, or the text ERROR
if the process cannot be started.
RunWait, C:\Program Files (x86)\AutoHotkey\AutoHotkey.exe "C:\script.ahk",, UseErrorLevel MsgBox %ErrorLevel%
In this example, the message box will display “1” if the file exists, or “0” if it is not.
source share