Jump to content

File Tracker


Recommended Posts

Hi ,

I am trying to create a File Tracker to track the file for containing Text(s).

My file is a continuously growing log file , so i need the tracker to not to stop and continue even after EOF is reached.

Means the Tracker should not stop anytime unless user says it so by closing it and continue monitoring the log file.

The Attached code works , but after sometime it gets into paused state .. which i dont know why. :D

The Program accepts file name as command line input(As it is invoked from another programme).

Thanks !!

temp.au3

Link to comment
Share on other sites

Pasting the code :

#include<array.au3>

#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#include <EditConstants.au3>

;$filename = StringReplace($cmdline[1],"'"," ")

$filename = $cmdline[1]

; to accept file names having space in between

for $i = 2 to UBound($cmdline) - 1

$filename = $filename & " " & $cmdline[$i]

Next

;MsgBox(0,"file",$filename)

$filehandle = FileOpen($filename)

;$filehandle = FileOpenDialog("","","")

; get input from user

$searchinput =InputBox("Enter Search Items","Enter Items in csv format to search multiple items" & @CR & "e.g. TORD1040592755,PHX01040583939,CreateDFOrder","")

;ConsoleWrite($searchinput & @CR)

$searcharray=StringSplit($searchinput,",",2)

$line = "" ; read line by line

Local $matchArray[65535][2]

;Local $insertitem[1][2]

$linecount = 1

$aArray=0

$arraycount=0

;code for gui creation

Opt("GUIOnEventMode", 1)

GuiCreate("Tracking - " & StringTrimLeft($filename,StringLen($filename)-23), 400,230)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")

GUISetState (@SW_SHOW)

$editbox=GuiCtrlCreateEdit("", 5,5,390,170,$ES_MULTILINE+$ES_WANTRETURN+$ES_AUTOVSCROLL+$WS_VSCROLL+$ES_READONLY)

$slider = GuiCtrlCreateSlider(5, 195, 200)

GUICtrlSetOnEvent(-1, "SetTrans")

GUICtrlSetData (-1, 100)

GuiCtrlCreateLabel("Transparency",70,180)

Func SetTrans()

ConsoleWrite(GuiCtrlRead($slider) & "%" & @CRLF)

ConsoleWrite(GuiCtrlRead($slider) * 2.55 & @CRLF)

WinSetTrans("", "", GuiCtrlRead($slider) * 2.55)

EndFunc

Func CLOSE()

Exit 0

EndFunc

;end code for gui creation

While True

$line = FileReadLine($filehandle)

;ConsoleWrite($line)

if @error = -1 Then

ConsoleWrite("EOF")

sleep(100)

Else

for $j = 0 to UBound($searcharray) - 1

if(StringInStr($line,$searcharray[$j])) > 0 Then

GuiCtrlsetdata($editbox,$searcharray[$j] & " found at line # " & $linecount & @CRLF,1)

EndIf

;Next

Next

$linecount = $linecount+1

EndIf

WEnd

Link to comment
Share on other sites

Hmm... I was suspecting that the integrity of the file pointer might not be maintained after a massive number of EOF reads, but after stripping out some of the fluff, this ran for an hour and still detected new matches added to the target file:

#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
;Global $filename = $cmdline[1]
Global $linecount, $listcount, $filename = @ScriptDir & "test.log"
; get input from user
$searchinput =InputBox("Enter Search Items","Enter Items in csv format to search multiple items" & @CR & "e.g. TORD1040592755,PHX01040583939,CreateDFOrder","")
$searcharray=StringSplit($searchinput,",")
; GUI ==============================================================================================================================
GuiCreate("Tracking - " & StringTrimLeft($filename, StringInStr($filename, "", 0, -1)), 400, 230)
$ListBox = GuiCtrlCreateList("", 5,5,390,170, BitOR($WS_BORDER, $WS_VSCROLL))
GUISetState (@SW_SHOW)
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE")
; MAIN =============================================================================================================================
$filehandle = FileOpen($filename)
While True
$line = FileReadLine($filehandle)
if @error = -1 Then ; EOF
  ToolTip("EOF") ; test
  sleep(50) ; test
  ToolTip("") ; test
  sleep(50)
Else
  $linecount += 1
  for $j = 1 to $searcharray[0]
   If StringInStr($line,$searcharray[$j]) > 0 Then
    Beep(800,50) ; test
    GuiCtrlsetdata($ListBox,$searcharray[$j] & "  found at line  #  " & $linecount)
    _GUICtrlListBox_SetTopIndex($ListBox, $listcount)
    $listcount += 1
   EndIf
  Next
EndIf
WEnd
FileClose($filehandle)
Exit
; SUBROUTINES +=====================================================================================================================
Func CLOSE()
    Exit 0
EndFunc

It is functionally no different than yours, so I'm at a loss as to the cause of your issue :D

Edited by Spiff59
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...