I have a job that I want to assign it to AHK to run for me in 5 minute intervals. It needs to check the contents of a txt file, lets say c:\test.txt. This file can contain any number of lines in the format of:
prog 1
prog 2
prog 3
...
prog N
among lines containing other pieces of text.
My purpose is to tell AHK the number right after the word prog, on the last line, which is the largest number in the list as these lines come in numeric sequence in this file.
My grandiose idea is to check the existence of lines from "prog 1" to "prog N", where N is a number under 20, using a series of find commands on a cmd window, get the errorlevel back and when errorlevel hits 1, I will set my desired variable to the value of the value of the loop index minus 1, as it was the last successfully ran find command, as such
i=1
loop 20
{
type c:\users\me\test.txt | find "prog "%i%
if %errorlevel% != 0
{
num := i-1
; exit the loop in some way here
}
else
{
i := i+1
}
} ; end loop
At this point, all I am interested in is the value stored in variable %num%. I know it may not be the most elegant solution to accomplish this but for a few runs everyday on an otherwise idle laptop, I can take the performance penalties.
So far, I am stuck at the very basic component of this idea: find command and passing the errorlevel it generates back to AHK
here is my code: (this code is only for the testing of find command, which I got from AHK forums)
Run %COMSPEC% /K type c:\users\me\test.txt | find "prog 4", , max
msgbox %ErrorLevel%
return
when this piece of code runs, the messagebox always displays the value "0" regardless "prog 4" line is there or not.
when I replace command Run with RunWait, then errorlevel gets displayed as one expects, but in that case, my automation process runs into a glitch: Expecting manual effort to close the cmd prompt, which I am assuming the *feature" of the Wait portion of the command RunWait.
How can I get over this hurdle ? I am open to loading the whole functionality to a dos batch file and getting a numeric output from the batch file at the end, but I came to realize, programming with AHK is much easier to do and to understand than that of DOS batch programming. So, my preference is on the AHK scripting side.
Thank you