Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-28-2019, 12:29 PM
Reno Reno is offline
Registered User
 
Join Date: Mar 2019
Posts: 27
Searching screen for Y position of a string?

I have a VBscript section where some text is being found on the screen and copied:
crt.Screen.Get(54,39,54,44)

I've found that the coordinate positions can vary. I'm not sure why and was guessing it might have something to do with CRT screen size or how big the "send command" area is.

If I'm looking for a line in a command output like "Total Connected Users: ", how could I get the (x,y,x,y) position values of that string to get the numbers after the colon+space?

For example, if the line looks like "Total Connected Users: 15", how would you search for the "Total Connected Users: " string to grab the (say) 4 characters after that string?

Thank you
Reply With Quote
  #2  
Old 03-28-2019, 12:49 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,019
Hi Reno,
Quote:
I've found that the coordinate positions can vary. I'm not sure why and was guessing it might have something to do with CRT screen size or how big the "send command" area is.
I don't think it has to do with SecureCRT. A column is a column is a column.

Is it the end of the line after the number? Or is there other output on the same line?

If that's the end of the line, you could probably do something like this:
Code:
crt.Screen.WaitForString "Connected Users: "
nUsers = crt.Screen.ReadString(vblf)
crt.Dialog.MessageBox nUsers
If there's other output on the same line, you would need to use VBScript's Left() function to just get the first four characters/digits of nUsers if that's the maximum possible digits (or use Split() if there's some "known separator" such as 4 spaces before next column of data).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-28-2019, 03:29 PM
Reno Reno is offline
Registered User
 
Join Date: Mar 2019
Posts: 27
Thank you, I will experiment. Two questions come to mind. I didn't mention I really need to grab two different pieces of data from the output.

1)After the WaitForString detects the string, and the data is copied, will a WaitForString to detect the return of the prompt work, or will it be looking to late for the return of the prompt?

2)I actually need to grab two pieces of information per command. I'm also wondering if the script would be fast enough to catch two strings as the appear, and then catch the return of the Unix Prompt.

Thanks for the help!
Reply With Quote
  #4  
Old 03-28-2019, 03:59 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,019
Hi Reno,
Quote:
1)After the WaitForString detects the string, and the data is copied, will a WaitForString to detect the return of the prompt work, or will it be looking to late for the return of the prompt?
I'm not sure what you mean. Did you mean to type ReadString() for the first WaitForString above?

If so, yes, because ReadString() is capturing up to the line ending so you can follow that with a WFS:
Code:
nUsers = crt.Screen.ReadString(vblf)
crt.Screen.WaitForString("My_prompt")

Quote:
2)I actually need to grab two pieces of information per command. I'm also wondering if the script would be fast enough to catch two strings as the appear, and then catch the return of the Unix Prompt.
That depends. I would need some actual info about what the output is and what you are trying to capture.

A better method might be to capture all the output and then use Split() to separate into lines and iterate over all lines of the output and parse out what you need:
Code:
ReadString until both items appear in output
split output on line ending into array
for each line in array of captured data
   if "item1" appears in data    ' use InStr
       ' Parse it out with Left()/Right()/Mid()
   else if "item2" appears in data
       ' Parse it out with Left()/Right()/Mid()
   else 
       discard line
   end if
next
The ToggleNoForEachLineInSelectionAndPaste.vbs script example in the scripting manual illustrates how to split on the line ending and iterate over an array.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 03-28-2019, 04:08 PM
Reno Reno is offline
Registered User
 
Join Date: Mar 2019
Posts: 27
I see the problem now for sure. If you'r cursor is at the prompt at the bottom of a window, the Y position of the cursor will be different every time if:
1) Different monitors with different resolutions
2) If the "send command" pane is made taller or shorter
3) if the SecureCRT window is made smaller or bigger.

So, it seems that using X,Y positioning to target getting text off the screen is completely unreliable and varies between monitor resolution, size of the "Send Command" pane and how big the user has the SecureCRT app open on the screen.
Reply With Quote
  #6  
Old 03-28-2019, 04:15 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,019
Hi Reno,
Quote:
2) If the "send command" pane is made taller or shorter
send command pane = Command Window?

#2 would only affect rows, not columns.

Quote:
So, it seems that using X,Y positioning to target getting text off the screen is completely unreliable and varies between monitor resolution, size of the "Send Command" pane and how big the user has the SecureCRT app open on the screen.
Why is your text "off-screen"?

What rows/columns and On resize option are configured in the Terminal / Emulation category of Session Options?

Do you mean your application window spans two monitors with different resolutions?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 03-29-2019, 09:49 AM
Reno Reno is offline
Registered User
 
Join Date: Mar 2019
Posts: 27
bgagnon,

I realized last night that I was looking at this wrong. I was thinking, that after the prompt returns, I should be scanning the screen by x/y positions to find what I need and grab it. Then it occurred to me, that what I should really be trying to do, would be capturing each line as it goes by into an array of CRT lines so that I could then leverage the VBscript array functions to search for the information I need inside the array.

I did a search on the forums with that new idea and found and example that was exactly what I needed to get started (from VanDyke/Mike). I just need to modify Mike's example script to add an array and then re-dim it for each new line, adding the new line to the new array position.

https://forums.vandyke.com/showthread.php?t=2147


Code:
#$language = "VBScript"
#$interface = "1.0"

crt.screen.synchronous = TRUE

Dim szOutput, szFinishedOutput, szCommand, szPrompt, nResult

Dim szStringArray

nIndex = 1
szOutput = ""
szCommand = "ls -1"
szPrompt = " $"

crt.screen.send szCommand & vbcr
nResult = crt.screen.waitforstrings(vbcr, vblf, 5)
szOutput = szOutput & crt.screen.readstring()

do
    szOutput = szOutput & crt.screen.readstring()
    if InStr(1, szOutput, szPrompt, 1) > 0 then exit do
loop

szStringArray = Split(szOutput, vbcr, -1, 1)

msgbox "Finished running command and collecting data..." & vbcr & _
        szOutput

Last edited by Reno; 03-29-2019 at 09:55 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 05:50 AM.