[Gambas-user] file read and growing logfile

Ron ron at ...1740...
Mon Mar 23 15:11:17 CET 2009


Ron schreef:
> 
> How to watch new data that's added to a logfile?
> 
> I want to make an apache log monitor, so I thought I could do that with 
> FILE READ WATCH, but thats not suited it seems, that one only seems keep 
> generating File_Read events continuous.
> 
> In short:
> I want to open a file readonly.
> Then seek to end of file (or just before it)
> Then only get file_read events when new lines/data are added (by apache)..
> 
> Anyone has any ideas?

In response to my own question I have tested with this:

It creates a file and reads it, event File_Read() keeps getting raised, 
even after end of file.

' Gambas module file
PRIVATE hFile AS File
PRIVATE hFile2 AS File

PUBLIC SUB Main()

   ' create test file
   hFile = OPEN "/tmp/file" FOR WRITE CREATE
   PRINT #hFile, "0123456789";
   CLOSE #hFile

   ' watch it
   hFile2 = OPEN "/tmp/file" FOR READ WATCH

END

PUBLIC SUB File_Read()

   DIM iByte AS Byte

   READ #hFile2, iByte
   PRINT " "; iByte;

END

It prints:
  48 49 50 51 52 53 54 55 56 57

And then gives error "End of File"

This is not what I expected, shouldn't it stop before end of file?

Gambas 2.12, gb.qt

Regards,
Ron_2nd.




More information about the User mailing list