Jump to content

Recommended Posts

Posted (edited)

Hello AutoIt Scriptwriters! 👋❤️

The log file of one of Server Managers is opened and now is writing by Server Manager

Log file contents are:

2019-03-21 Error!: Syntax not found!

2019-03-21 Error! Specified language not found! 

 

How can i make a script to check the log file every 1 second, if log file writes new line, then send a MsgBox that contains last written line by Server Manager? 

Edited by Colduction
Posted
  On 3/10/2019 at 8:11 PM, Exit said:

Use FileGetSize() in a loop with sleep(1000) to get filesize.

If it changes, open the file for read, position to EOF - deltasize with filesetpos()

Fileread() and display in messagebox

 

Expand  

Thanks bro! 

If you write these codes, it's better😓

Posted (edited)
  On 3/10/2019 at 8:29 PM, Colduction said:

If you write these codes, it's better😓

Expand  
  Reveal hidden contents

 

Edited by FrancescoDiMuro

Click here to see my signature:

  Reveal hidden contents

 

Posted (edited)
  On 3/10/2019 at 8:36 PM, FrancescoDiMuro said:
  Reveal hidden contents

 

Expand  

Excuse me my friend, but I'm noobie

I've just started AutoIt scripting in last week

Edited by Colduction
Posted

@Colduction

Sure, but that's not an excuse.

If you keep asking for code without putting any effort trying to do and, most important, to understand what you are trying to do, then you'll never understand what you are doing, and you'll always need someone who spoon the code for you (even if it's not a good thing to do here).

Do something, and if you need help, then post your code here.

Click here to see my signature:

  Reveal hidden contents

 

Posted
  On 3/10/2019 at 8:43 PM, FrancescoDiMuro said:

@Colduction

Sure, but that's not an excuse.

If you keep asking for code without putting any effort trying to do and, most important, to understand what you are trying to do, then you'll never understand what you are doing, and you'll always need someone who spoon the code for you (even if it's not a good thing to do here).

Do something, and if you need help, then post your code here.

Expand  

Thanks bro, Okay❤️👌

Posted

Actually you can just keep the file handle open and use readfile on it @extended will contain the characters read like so..

 

;Pseudo code
Global $g_sFile = "C:\Logfile.txt"
Global $g_hFile = FileOpen($g_sFile) ;Read Permissions
Global $g_iRetries = 60 ;Exits after 60 seconds with no new data

If $g_hFile < 0 Then
    MsgBox(0, "Error", "Can't open " & $g_sFile)
    Exit
EndIf

Global $g_sRead = ""

While $g_iRetries > 0
    $g_sRead &= FileRead($g_hFile, -1)
    ;@extended is set to the number of bytes/characters returned
    If @extended = 0 Then
        $g_iRetries -= 1
        sleep(1000)
    Else ;There is new data!!
        ConsoleWrite($g_sRead & @CRLF)
        $g_sRead = ""
        $g_iRetries = 60 ; reset wait count
    Endif   
WEnd
FileClose($g_hFile)

 

Posted
  On 3/10/2019 at 9:44 PM, Bilgus said:

Actually you can just keep the file handle open and use readfile on it @extended will contain the characters read like so..

 

;Pseudo code
Global $g_sFile = "C:\Logfile.txt"
Global $g_hFile = FileOpen($g_sFile) ;Read Permissions
Global $g_iRetries = 60 ;Exits after 60 seconds with no new data

If $g_hFile < 0 Then
    MsgBox(0, "Error", "Can't open " & $g_sFile)
    Exit
EndIf

Global $g_sRead = ""

While $g_iRetries > 0
    $g_sRead &= FileRead($g_hFile, -1)
    ;@extended is set to the number of bytes/characters returned
    If @extended = 0 Then
        $g_iRetries -= 1
        sleep(1000)
    Else ;There is new data!!
        ConsoleWrite($g_sRead & @CRLF)
        $g_sRead = ""
        $g_iRetries = 60 ; reset wait count
    Endif   
WEnd
FileClose($g_hFile)

 

Expand  

Thanks brother, Thanks🎉🍻

You've made my day🎊❤️

  • 1 month later...
Posted (edited)
  On 3/10/2019 at 9:44 PM, Bilgus said:

;Pseudo code Global $g_sFile = "C:\Logfile.txt" Global $g_hFile = FileOpen($g_sFile) ;Read Permissions Global $g_iRetries = 60 ;Exits after 60 seconds with no new data If $g_hFile < 0 Then     MsgBox(0, "Error", "Can't open " & $g_sFile)     Exit EndIf Global $g_sRead = ""  While $g_iRetries > 0     $g_sRead &= FileRead($g_hFile, -1)     ;@extended is set to the number of bytes/characters returned     If @extended = 0 Then         $g_iRetries -= 1         sleep(1000)     Else ;There is new data!!         ConsoleWrite($g_sRead & @CRLF)         $g_sRead = ""         $g_iRetries = 60 ; reset wait count     Endif   WEnd FileClose($g_hFile)

Expand  

excuseme, this script writes even old datas that already written by different program

can you guide me to only get new data?

Edited by Colduction

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
  • Recently Browsing   0 members

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