Sign in to follow this  
Followers 0
Mallikarjun

Repeating the sleep function

8 posts in this topic

Hi,

I am searching some text in the file that file is continuously updating(log file) ..if text not found in the file..it means it has to wait for some time and recheck the text 3 times...if found than exit the script...Is their any solution for this..Reply should be appreciate..

Thanks

Mallikarjun

Share this post


Link to post
Share on other sites



Mallikarjun,

Yes, there is a solution for this...where is your code?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

I would start with something like this:

$WaitTime = 60000
$StringToFind = "test"
$LogFileFullPath = "C:Templogfile.txt"

While 1
If _FindInFile($StringToFind, $LogFileFullPath) Then ExitLoop
Sleep($WaitTime)
WEnd

(Note that this only checks once every time, not three times.)

For the _FindInFile function, maybe take a look at an example script by guinness:

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

here is an example which reads the file in question until the string your looking for is found. it is only meant as a demonstration to learn from so don't just add it to your script and expect it to work. the way i tested it was using another script i made which changed the value in a script faster than the script checking the value.

here is my example:

$j = 0
While 1
    $bleh = bleh()                          ;call the function to check if the value is in the string
    ConsoleWrite($bleh & @CRLF)
    If $bleh == True Then                    ;if the file is in the string add 1 to the variable $j
        $j += 1
    Else
        $j = 0                              ;otherwise set it back to 0
    EndIf
    If $j >=3 Then Exit                    ;once the string has been found 3 times exit the script
    Sleep(300)
WEnd

Exit;just in case exit is never a bad thing to have

Func bleh()
    $var = FileRead(@ScriptDir & 'file1.txt');read the file
    If StringInStr($var, '1') Then;check if the file contains your string
        Return True;if yes, return true
    Else
        Return False;if no, return false
    EndIf
EndFunc

here is the other script to change the value in the file:

HotKeySet("{esc}", "_exit");so all you have to do is press escape when you want it to stop
While(1)
    Sleep(100)
    FileDelete(@ScriptDir & 'file1.txt')
    FileWrite(@ScriptDir & 'file1.txt', Random(0,1,1))
WEnd
Func _exit()
    Exit
EndFunc

to test like i did put the 2 scripts in a empty folder and run the script changing the value and then run the other one through scite.

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

...interesting that there have been 5 replies over several days without hearing froim the OP...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Maybe he's repeating his sleep function and hasn't woke up lol

Personally, I'd rather think of a logical way to avoid looping with a sleep statement.

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