Jump to content

Waiting for a log file to complete


Recommended Posts

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

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

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
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...