Jump to content

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


Pera
 Share

Recommended Posts

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

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

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

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

  • Moderators

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

FileRead()?

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.

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

  • Moderators

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

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.

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

Link to comment
Share on other sites

  • 3 weeks later...

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...