Sign in to follow this  
Followers 0
SpookMeister

Parsing a log file on the fly

5 posts in this topic

I currently have a script that is working fairly well, lets say that it is accurate 90% of the time, at detecting when a desired event is happening by reading visual clues from another program's display. However, I have recently learned that the program being monitored also has a logging option I can enable that would include (among many other things) the triggering of the event I want to catch. I would like to use this feature to improve my script's accuracy if I can, but I'm not sure how to proceed.

Does anyone have some advice/pointers on how I go about monitoring new data as it is added to this log file for the event I am looking for? I'm thinking that constantly re-reading the entire data file trying to get the new data will be far more CPU/HDD intensive than I can afford.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites



If the other program only outputs to a text file your real time logging options are limited. Depending on how the log file is updated it might not even be an option. Does the log file get written to in real time? Or does it write it all-at-once when the program wants to...

If it does write it real time it technically has to open and close the handle too. Likewise, you'd have to reopen the handle (re-read the file) to get any new information. It would be nice if the logging was piped to the output stream or something, but with a text file I don't know...

Share this post


Link to post
Share on other sites

Constantly check the log-file filetime (modified), if it has changed read the last (assumed new data is appended) some thousand byte with _WinAPI_CreateFile()+_WinAPI_SetFilePointer() and parse new results.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Constantly check the log-file filetime (modified), if it has changed read the last (assumed new data is appended) some thousand byte with _WinAPI_CreateFile()+_WinAPI_SetFilePointer() and parse new results.

Thanks KaFu,

This sounds like what I'm looking for. I'm looking at the help file now and will play with it, but at first glance implementation is not obvious to me (of the WinAPI parts). If you feel up to it, could you see your way to give a little example, even pseudo-code would be of great help.

Thanks again,

-Spook

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Nevermind KaFu,

Figured it out... was just scared I guess :)


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0