Alpinestar Posted March 16, 2009 Share Posted March 16, 2009 Hello I hope someone can help me. Basically my program waits for a process to complete and then reads the log file it generates. However I have noticed that sometimes the log file is still updating after the process has finished so I am only getting a portion of it. It could possible be another process that completes the update. So my question is, is there a way of identifying when the log file has completed like checking time/date of last modified / polling the file or just putting a timer in. Link to comment Share on other sites More sharing options...
D4rk^S0ul Posted March 16, 2009 Share Posted March 16, 2009 You could always stick a small loop in your program reading the file then reading it again several seconds later and comparing the two to see if it has changed and stop reading once it is the same as before but that will only work if your log file is updating constantly. Link to comment Share on other sites More sharing options...
Alpinestar Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks for the reply. I expecting the log file to finish being updated within 10 - 30 mins. Would this still be a suitable option, if so do you have any pointers that I should read up on to complete this. Link to comment Share on other sites More sharing options...
D4rk^S0ul Posted March 16, 2009 Share Posted March 16, 2009 (edited) All you need to do is create a while loop and put a if function and use fileread to read the file then compare it, eg: While 1 $BeforeFile = FileRead("Filepath\File.txt") Sleep(2000) $AfterFile = FileRead("Filepath\File.txt") If $BeforeFile = $AfterFile Then ; What to do when file has been checked 2 seconds later and is same as before Exitloop EndIf WEnd This is just a quick mock up and there are better ways to do it, also you will really want to put a fileopen somewhere. Edited March 16, 2009 by D4rk^S0ul Link to comment Share on other sites More sharing options...
Zedna Posted March 16, 2009 Share Posted March 16, 2009 (edited) In loop try to open file for writing without sharing to other processes.#Include <WinAPI.au3> While _WinAPI_CreateFile('C:\file.log', 2, 4, 0) = 0 Sleep(100) WEndEDIT:file handle should be closed#Include <WinAPI.au3> While 1 hFile = _WinAPI_CreateFile('C:\file.log', 2, 4, 0) If hFile <> 0 Then ExitLoop Sleep(100) WEnd _WinAPI_CloseHandle($hFile) Edited March 16, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Alpinestar Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks for all your replies Will give it a go tomorrow. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now