Sign in to follow this  
Followers 0
Tentaal

Read txt in real time

8 posts in this topic

Hi,

I'm looking for a way to watch a text file in real time.

I want to make a small tool that check log files in real time in a windows.

Thanks in advance for any help!

Share this post


Link to post
Share on other sites



It is possible. The easiest to implement way would be to keep a copy in memory, and read the text file every loop. Compare it to the original.

You could also check the last write time. That would be the most efficient in my opinion.

Share this post


Link to post
Share on other sites

I understand this :

$file = FileOpen("test.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend
FileClose($file)

But... I dont get the way to open a Windows and display the text inside it.

Share this post


Link to post
Share on other sites

Ok, I see that I missed something. Just make a GUI and put a label or edit into the GUI.

Instead of reading a character at a time and putting it into a MsgBox, put them all into a string.

While 1
$text += FileRead($file, 1)
If @error = -1 Then ExitLoop
WEnd
MsgBox(0, "", $text)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Mmm. this put the text on the GUI but show only one line

It does'nt make a return (CR)...

#include <GUIConstants.au3>

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

GUICreate("Test", 600, 300)

GUISetState(@SW_SHOW)

While 1

$line = FileReadLine($file)

GUICtrlCreateEdit ($line , 10, 10 , 590 , 290 )

sleep(2000)

If @error = -1 Then ExitLoop

WEnd

Edited by Tentaal

Share this post


Link to post
Share on other sites

Mmm. this put the text on the GUI but show only one line

It does'nt make a return (CR)...

Try this (not tested):

#include <GUIConstants.au3>

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

GUICreate("Test", 600, 300)
$edit = GUICtrlCreateEdit ($line , 10, 10 , 590 , 290 )
GUISetState(@SW_SHOW)

While 1
    $data = FileRead($file)
    GUICtrlSetData ($edit, $data)
    If @error = -1 Then ExitLoop
    sleep(2000)
WEnd

FileClose($file)

;finally show whole result
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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