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 07-05-2016, 12:00 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 80
Window Focus and Clipboard

I have a script that runs just fine (so, why am I bothering anyone?)

Here is the issue...

In the following code snippit:
Code:
'
    crt.Session.SetStatusText("Receiving Data...")
    crt.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
    crt.Screen.Send "cat " & strDevice & vbCr
    crt.Screen.WaitForString("RANCID-CONTENT-TYPE")
'
    intResult = crt.Screen.WaitForStrings("configs $ ", "cat: ", 250)

    Select Case intResult
        Case 0,2 ' Timeout or error from cat command
            Exit Sub
    End Select
'
    crt.Screen.SendSpecial "MENU_SELECT_ALL"
    crt.Screen.SendSpecial "MENU_COPY"
    arrData = Split(crt.Clipboard.Text, vbCrLf)
    crt.Screen.Send "cd" & vbCr & _
                    "clear" & vbCr
'
If SecureCRT looses keyboard focus, the "Select All" and "Copy" commands break.

Also, if I have multiple tabs open in SecureCRT, the "Select / Copy" isn't getting data from the correct tab.

Here is a completely different way that doesn't exhibit that symptom:
Code:
'
    crt.Session.SetStatusText("Receiving Data...")
    crt.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
    arrData = Split(CaptureOutputOfCommand("cat " & strDevice, sProwlName & ":"), vbCrLf)
'
And, the Function:
Code:
Function CaptureOutputOfCommand(szCommand, szPrompt)
    crt.Screen.Send szCommand & vbCr            ' Send command to the router.
    crt.Screen.WaitForString szCommand & vbCrLf ' Wait for the Command to be echoed by router.
    CaptureOutputOfCommand = crt.Screen.ReadString(szPrompt)            
End Function
This second method seems to slow down if there is a lot of data coming in (almost as if memory is filling up).

---

So, my question is: Which method is best? And, in the first method, how could I avoid the "focus" issue (should I specify the tab or something)?

A coworker helped me. "crt.Window.Activate", right before the "Select/Copy".

---

Since this is faster, I'll go with the first way is better.

Last edited by Rhudi; 07-05-2016 at 02:44 PM. Reason: Corrected "Focus" issue
Reply With Quote
  #2  
Old 07-11-2016, 09:32 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,359
Hi Rhudi,

The technique recommended by your colleague is one way.

Many of our example scripts illustrate "tab-safe" best practices, such as:

Code:
    ' Make this script tab safe
    Dim objTab
    objTab = crt.GetScriptTab
However, in your case, since you are working with multiple tabs, you also might want to prompt to be sure the correct tab is active:

Code:
Sub Main()
    Do
        ' Ask which tab to activate, by name/title/caption
        strTabName = crt.Dialog.Prompt("What is the name of the tab you would like to activate?", "Which tab?", strTabName)
        If strTabName = "" Then Exit Do
        
        ' Iterate through all tabs, searching for a match on the name"
        For i = 1 To crt.GetTabCount
            Set objTab = crt.GetTab(i)
            If objTab.Caption = strTabName Then
                objTab.Activate
                Exit Do
            End If
        Next
        
        ' Otherwise, display a message and ask for the name again.
        crt.Dialog.MessageBox("Tab named '" & strTabName & "' was not found!")
    Loop
End Sub
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
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 12:29 AM.