Sign in to follow this  
Followers 0
Pera

How to capture the text inside a .log file in real time?

15 posts in this topic

Hi there,

I am trying to get the text within a .log file that is being updated by the game as events progress. I used WinGetText;

[/autoit]
$TexttobeRead = WinGetText("Chat.log -", "")
[autoit]

However, as the chat.log updates it doesn't actually update in the open document. Is there a way to capture the text within chat.log in real time? I than would like to use StringInStr to compare the text with a substring.

Thanks in advance

Share this post


Link to post
Share on other sites



You could create a loop that would continuously check

I did the loop with WinGetText, however when I have the "chat.log" open, whatever is in the open file is actually being captured by WinGetText. In the meantime the game is still updating chat.log on the background but the updates doesn't display in the open file. I hope it makes sense...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh, I see. Have you tried using a "read string"-type command?

EDIT: I don't know if I'm giving the correct term...

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Oh, I see. Have you tried using a "read string"-type command?

EDIT: I don't know if I'm giving the correct term...

I am not sure if I know any string commands that will get the text within a file?

Share this post


Link to post
Share on other sites

I am not sure if I know any string commands that will get the text within a file?

I really appreciate for even the smallest tip on this... I have been working on it forever heh...

Share this post


Link to post
Share on other sites

I really appreciate for even the smallest tip on this... I have been working on it forever heh...

FileRead()?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

FileRead()?

Well I tried this real fast to test it and it doesn't open "chat.log", actually when I run the script, nothing happens...

[/autoit]
$file = FileOpen("chat.log", 0)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($file)
[autoit]

Share this post


Link to post
Share on other sites

I'm not sure whether you want to read Window Text or text file...

Try this it should be fine if it's log and appending to the end...

#include <File.au3>

Dim $aChatlog, $TotalLine
$chatlog = @ScriptDir & "\chat.log"
$TimeStamp = FileGetTime($chatlog, 0, 1)
_FileReadToArray($chatlog, $aChatlog)
$TotalLine = $aChatlog[0]
While 1
    If FileGetTime($chatlog, 0, 1) <> $TimeStamp Then
        $TimeStamp = FileGetTime($chatlog, 0, 1)
        _FileReadToArray($chatlog, $aChatlog)
        If IsArray($aChatlog) Then
            $newLines = ""
            For $i = $TotalLine To $aChatlog[0]
                $newLines &= $aChatlog[$i] & @CRLF
            Next
        EndIf
        MsgBox (0,"Changed","New line(s) : " & @CRLF & $newLines)
    EndIf
    Sleep(1000)
WEnd

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hey thanks fo rthe script. I tried it and it gives an error in line 7...

Edited by Pera

Share this post


Link to post
Share on other sites

Hey thanks fo rthe script. I tried it and it gives an error in line 7...

I think you are having a problem reading a file.

change this section and try.

#include <File.au3>

Dim $aChatlog, $TotalLine
$chatlog = @ScriptDir & "\chat.log"
$TimeStamp = FileGetTime($chatlog, 0, 1)
If Not _FileReadToArray($chatlog, $aChatlog) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
$TotalLine = $aChatlog[0]

Share this post


Link to post
Share on other sites

I think you are having a problem reading a file.

change this section and try.

#include <File.au3>

Dim $aChatlog, $TotalLine
$chatlog = @ScriptDir & "\chat.log"
$TimeStamp = FileGetTime($chatlog, 0, 1)
If Not _FileReadToArray($chatlog, $aChatlog) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
$TotalLine = $aChatlog[0]
I am getting message "error reading log to array: 1". Sorry I am causing a lotof trouble...

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

You don't have the right file location more than likely. All of the options provided will work, but you have to replace:

$chatlog = "Change This to the actual location, not just "chat.log""oÝ÷ ØGbµ§¶¬jëh×6Global $hChatLog = 'chat.log', $sString = ''
If Not FileExists($hChatLog) Then
    MsgBox(16, 'Error', 'File Does not exist here')
    Exit -1
EndIf
$sString = FileRead($hChatLog)
MsgBox(64, 'Info', 'File Contains: ' & @CR & @CR & $sString)
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

You don't have the right file location more than likely. All of the options provided will work, but you have to replace:

$chatlog = "Change This to the actual location, not just "chat.log""oÝ÷ ØGbµ§¶¬jëh×6Global $hChatLog = 'chat.log', $sString = ''
If Not FileExists($hChatLog) Then
    MsgBox(16, 'Error', 'File Does not exist here')
    Exit -1
EndIf
$sString = FileRead($hChatLog)
MsgBox(64, 'Info', 'File Contains: ' & @CR & @CR & $sString)
Guys I really appreciate all of your help. I finally figured this out. My file location was incorrect. Well it was correct but it was under a different user account than what I used :)

Thanks a lot once again!

Share this post


Link to post
Share on other sites

Check out ABLogFile at www.amleth.com free realtime log file reader with nice options.

Hope this helps, at least to see it in action.

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