Jump to content

Reading output from text file continuously


Recommended Posts

Hi all,

first question in this forum, please don't give me the "Please read the tutorials", done that already.

So, what I am trying to do is open a Putty terminal (where logging is enabled), throw some commands, and watch the terminal output on an Edit box I have on my GUI.

I'm using:

$script_log = GUICtrlCreateEdit("", 104, 360, 425, 81)

$hps2_log = FileOpen("C:\Program Files\PuTTY Connection Manager\hps2.log", 0)

; check if file opened for reading OK

If $hps2_log = -1 Then

MsgBox(0, "Error", "Please check that Putty logging is enabled for this session.")

Exit

EndIf

; check if file creation is successful

$hps2_log_read = FileRead($hps2_log)

GUICtrlSetData($script_log, $hps2_log_read)

But this will only print the output from the terminal up to the specific point in the code. I want it to update continuously.

If I put it in a while loop, it just refreshes so fast that it is rendered invisible. I want my Edit box to append any new info from the Putty log at any time. How is this possible?

Link to comment
Share on other sites

You mean?

$script_log = GUICtrlCreateEdit("", 104, 360, 425, 81)

$hps2_log = FileOpen("C:\Program Files\PuTTY Connection Manager\hps2.log", 0)

; check if file opened for reading OK

If $hps2_log = -1 Then

MsgBox(0, "Error", "Please check that Putty logging is enabled for this session.")

Exit

EndIf

; check if file creation is successful

While 1

$hps2_log_read = FileRead($hps2_log)

GUICtrlSetData($script_log, $hps2_log_read)

WEnd

This will update every millisecond or so. Wouldn't it be a problem?

Isn't there a way to have a loop which reads the input from a file (when new input is feeded) and appends every new line to another file?

Thanks for your help!

Link to comment
Share on other sites

The simplest way:

$script_log = GUICtrlCreateEdit("", 104, 360, 425, 81)$hps2_log = FileOpen("C:\Program Files\PuTTY Connection Manager\hps2.log", 0)



; check if file opened for reading OK
If $hps2_log = -1 Then
 MsgBox(0, "Error", "Please check that Putty logging is enabled for this session.")
 Exit
EndIf
; check if file creation is successful

Dim $hps2_log_read, $hps2_log_read_prev

While 1
 $hps2_log_read = FileRead($hps2_log)
 If $hps2_log_read <> $hps2_log_read_prev Then
    GUICtrlSetData($script_log, $hps2_log_read) 
    $hps2_log_read_prev = $hps2_log_read
 EndIf
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...