Jump to content

Checking last line for text


 Share

Recommended Posts

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here



;$x = 1
;while $x < 10
Sleep(200)


$log = "C:\Users\Daniel\Desktop\log"
$lastline = FileReadLine($log, -1)
$file = FileOpen($log, 0)
$read = FileRead($file)


   If StringRegExp($lastline, "Start") AND StringRegExp($lastline, "start") Then
      Send("S")
   Else
      ConsoleWrite("Fail" & @LF)
   EndIf


;$x= $x + 1

;WEnd

;$hFile = FileOpen($log, 2)
;FileClose($hFile)

Edited by Dgameman1
Link to comment
Share on other sites

Try it like this...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <date.au3>
#include <array.au3>

; create some test data

local $bGen = false
if $bGen then _GenTestData()

; start of your program ---------------------------------------------------------------------------

local $st = timerinit()
$alog = stringsplit(fileread(@scriptdir & '\test.txt'),@crlf,1)
if stringregexp($alog[$alog[0]-1],'(?i)start') then
    ConsoleWrite('Found start' & @LF)
Else
    ConsoleWrite('Fail' & @LF)
endif
ConsoleWrite(stringformat('Time to test for string = %2.4f',timerdiff($st)/1000)  & @LF)

; end of your program -----------------------------------------------------------------------------

func _GenTestData()
    local $st = timerinit()
    filedelete(@scriptdir & '\test.txt')
    local $aWords = stringsplit(fileread(@scriptdir & '\wordlist.txt'),@crlf,1), $sOut
    for $1 = 1 to 1000
        $sOut &= _now() & ' '
        for $2 = 1 to random(10,20,1)
            $sOut &= ' ' & $aWords[random(0,$aWords[0],1)]
        Next
        $sOut &= @CRLF
    next
    $sOut &= _now() & ' ' & ' Start' & @crlf
    filewrite(@scriptdir & '\test.txt',$sOut)
    ConsoleWrite(stringformat('Time to gen test data = %2.4f',timerdiff($st)/1000)  & @LF)
endfunc

kylomas

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

Link to comment
Share on other sites

Try like this (regexp changed)...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here



;$x = 1
;while $x < 10
Sleep(200)


$log = "C:\Users\Daniel\Desktop\log"
$lastline = FileReadLine($log, -1)
$file = FileOpen($log, 0)
$read = FileRead($file)


   If StringRegExp($lastline, "(?i)Start")  Then
      Send("S")
   Else
      ConsoleWrite("Fail" & @LF)
   EndIf


;$x= $x + 1

;WEnd

;$hFile = FileOpen($log, 2)
;FileClose($hFile)

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

Link to comment
Share on other sites

because it cannot be both "Start" and "start".  The "(?i)" tells the regexp to be case insensitive.

edit: what's with the extraneous fileopen, read and sleep?

edit2: you could also have used "or" instead of "and"

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

Link to comment
Share on other sites

FYI,

Your script could be reduced to this...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


$log = @scriptdir & '\test.txt'
( StringRegExp(FileReadLine($log, -1), "(?i)Start") ) ? Send("S") : ConsoleWrite("Fail" & @LF)
;;SSSSS
Edited by 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

Link to comment
Share on other sites

 

FYI,

Your script could be reduced to this...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.10.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


$log = @scriptdir & '\test.txt'
( StringRegExp(FileReadLine($log, -1), "(?i)Start") ) ? Send("S") : ConsoleWrite("Fail" & @LF)
;;SSSSS

That seems beautiful except that if I'm looking for the letter S, even if the word has the letter S in it, it catches that =/

Link to comment
Share on other sites

That seems beautiful except that if I'm looking for the letter S, even if the word has the letter S in it, it catches that =/

 

and you would expect that if you are looking for the letter S and a word has the letter S in it, not to find it????

edit: and you are introducing additional search criteria...

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

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...