Constantly read a perpetually written to txt file
#1
Posted 06 November 2010 - 03:20 AM
The emulation software (AnzioLite) has a capture function, which constantly writes the screen output to a text file.
I was thinking about a file-reading loop, but the longer the window is open, the larger the file gets. I would only want text that was written to that file from the last page or two.
I'm sorry, I know this isn't much info to go on, so I'll come back and elaborate after sushi!
I just wanted to put this out there- is there some way to constantly read the text that is getting sent back and forth from the terminal and the server?
#2
Guests
Posted 06 November 2010 - 03:58 AM
Then use FileReadLine and keep track of last line read.
A little sloppy but it might work.
#3
Posted 06 November 2010 - 07:17 AM
If it isn't always locked, you could rename the file every-so-often.
In the process, you end up with a small file to read.
#4
Posted 09 November 2010 - 12:05 AM
Thanks, I'll check that out.You can probably use something like WatchFolder() (it should work when a file in a directory is changed).Then use FileReadLine and keep track of last line read.
Good idea- I tried it, but windows does say the file is locked.Do some tests to see if the file is continuously locked.
If it isn't always locked, you could rename the file every-so-often. In the process, you end up with a small file to read.
#5
Posted 09 November 2010 - 01:45 AM
So, are you only wanting to read the newly written data? If you are using AutoHotkey_L, you could try this:Constantly read a perpetually written to txt file
File := FileOpen("File.txt", "r")
File.pos := File.length
Loop,
if (File.pos < File.length)
TrayTip, Written:, % File.Read()
else
sleep, 100
Esc::
File.close()
ExitAppAfter this script starts, it will read any new data that is written to the file. However, if the other app locks the file, this might not work...
#6
guest3456
Posted 18 November 2010 - 05:06 AM
originally from: http://de.autohotkey.../topic4619.html
looks like its based off: http://www.autohotke...opic.php?t=7549
f3::
newtext := FileTail("C:\Program Files\mytextfile.txt")
if (newtext) {
Loop, parse, newtext, `n, `r
{
line := A_LoopField
linenum := A_Index
;..
}
}
return
FileTail(File) {
Static OPEN_EXISTING := 3
Static GENERIC_READ := 0x80000000
Static FILE_SHARE_READ := 1
Static FILE_SHARE_WRITE := 2
Static FILE_SHARE_DELETE := 4
Static FILE_BEGIN := 0
Static INVALID_HANDLE_VALUE := -1
Static CF := "" ; Aktuelle Datei (Current File)
Static FP := 0 ; Aktuelle Position in der Datei (File Pointer)
FH := 0 ; Dateihandle (File Handle)
FS := 0 ; Dateigröße (File Size)
FC := "" ; Inhalt der gelesenen Zeilen (File Content)
CL := 0 ; Länge des gelesenen Zeilen (Content Length)
If (File != CF) {
CF := File, FP := 0
}
FH := DllCall("CreateFile"
, "Str", File
, "UInt", GENERIC_READ
, "UInt", FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE
, "UInt", 0
, "UInt", OPEN_EXISTING
, "UInt", 0
, "UInt", 0)
If (FH = INVALID_HANDLE_VALUE) {
CF := "", FP := 0
MsgBox, 262160, FileTail, Die Datei %File% konnte nicht geöffnet werden!
} Else {
DllCall("GetFileSizeEx"
, "UInt", FH
, "Int64P", FS)
If (FP = 0 Or FS <= FP) {
FP := FS
} Else {
DllCall("SetFilePointerEx"
, "UInt", FH
, "Int64", FP
, "UInt", 0
, "UInt", FILE_BEGIN)
CL := VarSetCapacity(FC, FS - FP, 0)
DllCall("ReadFile"
, "UInt", FH
, "UInt", &FC
, "UInt", CL
, "UIntP", CL
, "UInt", 0)
DllCall("CloseHandle", "UInt", FH)
VarSetCapacity(FC, -1)
FP := FS
}
}
Return FC
}




