Retrieving text from a terminal window

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
kmarlowe
Newbie
Posts: 5
Joined: Tue Jun 30, 2020 7:34 pm

Retrieving text from a terminal window

Post by kmarlowe » Thu Jul 02, 2020 2:25 pm

Need to know when the terminal window I'm running my scripts against returns a different value than the default. For example, in the first screen capture below, the terminal gives a COMMENTS: prompt and my script can just start entering data:

Select EQUIPMENT INV. ENTRY NUMBER: 40563
PHYSICAL INVENTORY DATE: APR 16,2020// 7/2/2020 (JUL 02, 2020)
COMMENTS:
1>new comment goes here
2>cr on a blank line exits this mode
3>
EDIT Option:

In this example, because there are already comments against this record, the terminal returns the prompt "EDIT Option" (and I then have to script editor commands):

Select EQUIPMENT INV. ENTRY NUMBER: 39772
PHYSICAL INVENTORY DATE: JUL 2,2020// 7/2/2020 (JUL 02, 2020)
COMMENTS:
1>old comment here
EDIT Option: i
Insert after line: 0
1>new comment here
2>^ to exit this mode
1 line(s) inserted....
EDIT Option:

How do I detect what text prompt is currently on the screen next to the cursor? A user would see it and know how to proceed. I could use GetTextAtPoint or GetTextinRect and try to predict the screen coordinates where the cursor is appearing, but that seems kludgy. I could screen scrape and try to find the prompt text in the bottom of the scrape - also kludgy. Appreciate any ideas. Thanks - KLM

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Retrieving text from a terminal window

Post by Grovkillen » Thu Jul 02, 2020 4:54 pm

I don't know if you could use the pipe " | " to pipe the terminal output to a file or the clipboard. I use this all the time but I don't know if your particular use case apply.
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Retrieving text from a terminal window

Post by PepsiHog » Fri Jul 10, 2020 7:41 pm

@ kmarlowe,
You could use the Screen OCR Wizard to get the text from the console window. You could then process the text info as you see fit. Screen OCR is easy to use because of the wizard that helps you create the command.

I used VLC with the console window and then grabbed the text from that window.

Code: Select all

 //GetWindowList>wl
//mdl>%wl%

//C:\Program Files (x86)\VideoLAN\VLC\vlc.exe

OCRWindow>C:\Program Files (x86)\VideoLAN\VLC\vlc.exe,strText

mdl>%strText%
As far as where the cursur is, wouldn't the cursur be on the last line?


Good Luck,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
PepsiHog
Automation Wizard
Posts: 511
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Retrieving text from a terminal window

Post by PepsiHog » Fri Jul 10, 2020 7:59 pm

Ok, Here's more on the last idea.

Use sendtext to send some "text" that there is no way would be there otherwise. Then use OCRWindow to get all the text. By processing the text, the sent text will tell what the prompt before it is.

Once you know the prompt you need to answer, you can use Press> to send the needed number of backspaces to remove the sent text.

Now you can proceed with answering the prompt.

PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts