Jump to content
Sign in to follow this  
Matterz

Reading from an active file?

Recommended Posts

Matterz

Hey all,

I'm fairly new to AutoIt. I've been writing scripts and searching this forum constantly for the last week. However, I haven't been able to find a good solution for my script yet.

Basically I am running a program that writes to a log file. I'd like my AutoIt script to parse the file and react when certain words are found.

I tried using FileOpen() and FileRead() with the marker pointing to the last line. However, the program is constantly writing to the file and making my AutoIt script constantly read and possible miss lines or read the same line repeatedly seems like a bad approach.

Is there a way to be constantly monitoring what is written to the file other than using repeated FileRead() [or FileReadLine()] commands?

----

I hope my question is clear. Thanks for any advice.

Share this post


Link to post
Share on other sites
PsaltyDS

Hey all,

I'm fairly new to AutoIt. I've been writing scripts and searching this forum constantly for the last week. However, I haven't been able to find a good solution for my script yet.

Basically I am running a program that writes to a log file. I'd like my AutoIt script to parse the file and react when certain words are found.

I tried using FileOpen() and FileRead() with the marker pointing to the last line. However, the program is constantly writing to the file and making my AutoIt script constantly read and possible miss lines or read the same line repeatedly seems like a bad approach.

Is there a way to be constantly monitoring what is written to the file other than using repeated FileRead() [or FileReadLine()] commands?

----

I hope my question is clear. Thanks for any advice.

Two obvious possibilities:

1. Read to an array with _FileReadToArray(), keeping track of what line was last checked and only review the array from that index forward.

2. Keep track of how many lines there are in the file with _FileCountLines() and only read new lines with FileReadLine().

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Matterz

Hmm Ok,

The program writes to the log file multiple times per second. I was hoping to get around constant FileRead() calls. If this is the way to go though then I'll give it a shot and see how it works out.

Thanks for the response!

Share this post


Link to post
Share on other sites
PsaltyDS

If you are up to working with WMI and COM objects, you could monitor FSO (File System Object) events to trigger checking the file every time it gets written to. That's not something you would typically recommend to someone new to scripting or AutoIt, though.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  

×