Jump to content

How can I automatically select only a specific block of text?


Recommended Posts

Hey, folks!

I am working on a project where this AutoIt script is interacting with a console which performs text searches in an indexed body of documents.

I presently have a list of search results in the console window. Conveniently, the search results are within a marker called "Results." So, the line immediately preceding the first search result, the console window displays "<Results>" (sans quotes); likewise, the line immediately after the last search result, the console window displays "</Results>" (sans quotes).

What I want to be able to do is automatically select ONLY the search results, which are encapsulated in the "Results" markers; I will then copy the search results into Windows Clipboard, then paste them into another application to parse the results. Therefore, I don't want to include the "Results" markers in the copied text.

Is there a way this can be done?

Thank you very much for your help!

Most graciously...

RGBreality

Link to comment
Share on other sites

Is it just displaying an XML file? If so, then just parse the XML directly either with string functions or the XMLDOMWrapper.au3 UDF.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

No, it's not an XML file. Presently it is displayed only on a console for this search application. It is displaying the search results. One "hit" for a search result is displayed on one line of text, and each line of text has six attributes about the "search hit" (such as the file name, directory the file is located, file size, etc.). Each of these six attributes are separated by a group of spaces (about five, though it varies depending on how long the file name and directory attributes are).

So, is there any way to parse this text, so that it could be displayed in an Excel-like spreadsheet?

Thank you for your help!

Most graciously...

RGBreality

Link to comment
Share on other sites

Hey, PsaltyDS!

It is indeed a command line window. Presently I'm having it launched from a different application. Are you saying that I should have AutoIt run the application?

I should first explain that I am a TOTAL AutoIt newbie (I've been using it for less than a week now!). So, to quote the late Phil Hartman's Attorney-Caveman persona, "All your big words scare me."

So, after some experimentation, I am indeed able to launch this console application through AutoIt. However, when I try to use the "StdOutRead" function, I receive an error, "Error: Error parsing function call." Is that because I didn't have a proper parameter after the function? Or did I do something else wrong?

EDIT: So, after reading the function parameters in AutoIt documentation, I tried "StdoOutRead" again. I received another error: "StdOutRead(application.exe)^Error". A second error reads, "Error: Illegal text at the end of statement (one statement per line).

So, what does "StdOutRead()" do? (I guess that captures the console display output?) Or does it parse the display output?

Thank you again for your help!

Most graciously...

RGBreality

Edited by RGBreality
Link to comment
Share on other sites

Did you try the example script under StdOutRead() in the help file?

You need to post your code (appropriately sanitized of personal/security information) so we can see what you are trying, in order to see where the errors are coming from.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, it looks like I accidentally had a Mouse call attached to the end of the "StdOutRead" call. Once I ran it again, I did not receive any errors. Here is the text I placed:

StdoutRead(applicationpath.exe)

I did not use any of the parameters.

Once the script ended, I was left with the console window, so I am not sure if the text it captured is in memory? Or how do I acquire the text, and then parse it for placement into a spreadsheet (or grid) format?

Thank you again for all your help!

Most graciously...

RGBreality

Link to comment
Share on other sites

So the answer is "No", you didn't use the example from the help file under StdOutRead(). :blink:

That would have looked more like:

#include <Constants.au3>

Global $iPID = Run("C:\Program Files\App\AppDir\App.exe", "C:\Program Files\App\AppDir", @SW_MINIMIZE, $STDERR_CHILD + $STDOUT_CHILD)

Global $line = ""
While 1
    $line = StdOutRead($iPID)
    If @error Then ExitLoop
    MsgBox(0, "StdOutRead: " & $iPID, $line)
Wend

While 1
    $line = StdErrRead($iPID)
    If @error Then ExitLoop
    MsgBox(0, "StdErrRead: " & $iPID, $line)
Wend

MsgBox(0, "Debug", "Exiting...")

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hmmm... I'm not sure I placed your code in correctly... Here is what I have now:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",2)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
#include <Constants.au3>
Global $iPID = Run("C:\application.exe", "C:\apppath", @SW_MINIMIZE, $STDERR_CHILD + $STDOUT_CHILD)
MouseMove(80,38)
MouseDown("left")
MouseUp("left")
Send("update{SPACE}{SHIFTDOWN}u{SHIFTUP}ltimus{SPACE}{SHIFTDOWN}a{SHIFTUP}daptive{SPACE}{SHIFTDOWN}bpm{SPACE}s{SHIFTUP}uite{SPACE}8{SPACE}{SHIFTDOWN}d{SHIFTUP}ocumentation{ENTER}open{SPACE}{SHIFTDOWN}u{SHIFTUP}ltimus{SPACE}{SHIFTDOWN}a{SHIFTUP}daptive{SPACE}{SHIFTDOWN}bpm{SPACE}s{SHIFTUP}uite{SPACE}8{SPACE}{SHIFTDOWN}d{SHIFTUP}ocumentation{ENTER}")
Global $line = " "
While 1
    $line = StdOutRead($iPID)
    If @error Then ExitLoop
    MsgBox(0, "StdOutRead: " & $iPID, $line)
WEnd

While 1
    $line = StdErrRead($iPID)
    If @error Then ExitLoop
    MsgBox(0, "StdErrRead: " & $iPID, $line)
WEnd

MsgBox(0, "Debug", "Exiting...")

When I run this, my mouse strokes don't function correctly, in that it doesn't move to the console window. Then it wrecks havoc with my other windows as it goes through its routine. :blink:

I do see that when the script runs, I get these small Title bar-like windows on the top of my screen. I get a whole series of them, and as I close them, I see sometimes they have arrows (probably the cursor from the console window).

So, what did I inadvertantly change to mess up my mouse strokes?

EDIT: I think one problem I have is with the console window itself. Each time the console window is launched (either manually or by script), it opens in a different screen location. So the initial mouse stroke misses it. I also wonder if the initial mouse stroke takes place before the console window is entirely loaded. Perhaps I should put a short delay before the mouse is moved? Or is there some way to always position the console window in the same screen location when it is launched?

RGBreality

Edited by RGBreality
Link to comment
Share on other sites

Now when I run the script, I see the console window and the mouse (barely) clicks within it. But I don't see any text display in it. (I assume the text is being captured by the small StdOutRead window on the top of the screen.)

I assume the script completes properly, though I have no way of verifying that. When I try to access (such as double-click) the StdOutRead window, it doesn't open or display any text. Furthermore, the console window remains empty (except for a blinking cursor). I can close the window and the StdOutRead window without any problems.

I think one issue that may be taking place is that the script is not taking any user input to run a search (which would ultimately be captured). Before making these changes, I had two scripts set up: one to load the search index, and then a second to paste what was in Windows Clipboard and send a "search" command for the console window. (The initial search string is entered by the end user, which that third-party application sends to Windows Clipboard) for the script to access.)

So, I think there is a missing piece in this existing script: this script must pause until it somehow knows that a search is to take place. Perhaps if there was a way for this script to detect new content in the Windows Clipboard?

Knowing that the StdOutRead function must be associated with the Run function, I can't have two separate scripts anymore.

Here's another related question: Is there a way I can "paste the contents of the Windows Clipboard" without having to perform a right-click on the console's Title bar, then select the "Paste" option? (When I attempt to do a CTRL-V keystroke, that is exactly what displays; the Clipboard contents do not come across.)

Thank you again for all your help with this! I really appreciate it!

Most graciously...

RGBreality

Link to comment
Share on other sites

I don't think I'm understanding what you're doing at all. Since I don't know anything about this app or its console, I can't help much with this.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hey, PsaltyDS!

I thought it might have become confusing, so I started a new thread which outlines the planned goals for this script. You can read that thread here: http://www.autoitscript.com/forum/index.php?showtopic=116896.

I hope you're able to give me some ideas on how to proceed!

Most graciously...

RGBreality

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