Sign in to follow this  
Followers 0
Alpinestar

Waiting for a log file to complete

6 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by D4rk^S0ul

Share this post


Link to post
Share on other sites

#5 ·  Posted (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)
WEnd

EDIT:

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 by Zedna

Share this post


Link to post
Share on other sites

Thanks for all your replies :P

Will give it a go tomorrow.

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