#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
Hi Reno,
Quote:
![]() 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
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#3
|
|||
|
|||
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! |
#4
|
|||
|
|||
Hi Reno,
Quote:
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:
![]() 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
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
#5
|
|||
|
|||
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. |
#6
|
|||
|
|||
Hi Reno,
Quote:
#2 would only affect rows, not columns. Quote:
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 |
#7
|
|||
|
|||
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. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|