Sign in to follow this  
Followers 0
goldfire

reading specific lines from a log

6 posts in this topic

i'm trying to write a program that will send a command to one window, based on input from a seperate window.

the window being operated upon will always be in focus, whereas the other window must be in the background.

I'm having no problems operating on the main window, as it pretty much only requires the Send command, but i'm finding it difficult to read what i need from the other window.

The window i want the script to read from is a running log, and i want the script to activate whenever a certain string is logged to the window. the problem is, the information in the window isn't saved anywhere, and i can't find a way for AI to constantly read the last line of the window to match against what i'm looking for. I'd also like to know if the program will be too CPU-intensive (the only way i can see it working is sending the line to a variable, and i'm going to assume that updating a variable 10 times per second can get stressful)

If i'm not explaining myself well, let me know, i'll give an example of what i want to do. Also, I'm new to all this, so if it's a silly problem, feel free to direct me to where in the helpfile it's explained B)

Share this post


Link to post
Share on other sites



can you just post a part of your code?

btw if your receiving the data in your 2nd window just let it check everytime you get a new message if there's the desired string in it

if stringinstr($income, "desire") then
;do what you like it to do
endif

i think thats the easiest way as long as i don't know your script

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I haven't been able to write any code yet as the script relies on the unknown function.

From how i understand it, stringinstr will be true whenever the entire string contains an instance of what i'm searching for. unfortunately, the entire string is essentially an open text file that is being written to a few times each second, and the string used to activate the script will occur multiple times.

Is there a way to search only the final line in an open window using AutoIt?

hm...as i wrote this, i noticed i had overlooked the WinGetText function. i'm going to see how far i get with this, but if anyone has any efficient ways to pull only one line of a full window's text, i'd be happy to hear them.

Edit: yea, silly newb mistake, should have kept reading the help file. a combination of wingettext and stringright will do the trick. thanks for your suggestion, though, Nuffilein

Edited by goldfire

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

right now i'm looking at:

While 1
    $log = WinGetText("background title")
    $string = String('my string, written in RegExp')
    $line = StrRight($log, maximum length of $string)
    If StringRegExp($line, $string, 0) = 1 Then
        Send("key")
    EndIf
WEnd

I think that's the basic code for what i want to do, i need to finish writing and debugging it (probably going to have a fun time with the RegExp). If you can see any major flaws in it right now, let me know. Specifically, though, i'd like to know if this will $log be refreshed after every loop, how often will it loop, and how much CPU will this eat if it does in fact constantly refresh itself?

Edited by goldfire

Share this post


Link to post
Share on other sites

While 1
    $log = WinGetText("background title")
    $string = String('my string, written in RegExp')
    $line = StrRight($log, maximum length of $string)
    If StringRegExp($line, $string, 0) = 1 Then
        Send("key")
    EndIf
WEnd

I think that's the basic code for what i want to do, i need to finish writing and debugging it (probably going to have a fun time with the RegExp). If you can see any major flaws in it right now, let me know. Specifically, though, i'd like to know if this will $log be refreshed after every loop, how often will it loop, and how much CPU will this eat if it does in fact constantly refresh itself?

$log is refreshed at the beginning of each loop.

(While 1) = It will loop indefinitely unless you have an exit (Adlib function or hotkey)

It will be extremely CPU intensive, as there is no wait condition.

Also, Send only works for the active window.

You should either activate the window or use ControlSend.

(Use Au3info to get the control names)


[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Thanks for the pointers guys. I've finished the project, and it works pretty well for my first real script.

To Skruge: The while loop is necessary, as i need to have $log and $line updated almost constantly to allow for how quickly the log will change. Yes, it is CPU intensive, but it doesn't slow my machine down at all until it jumps into the IF statement. Also, the program was written with the assumption that the main window will always be in focus, and with the requirement that it be as fast as possible. Thank you for your input, though.

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