VanDyke Software Forums

VanDyke Software Forums (
-   Scripting (
-   -   output delay after crt.Screen.Send (

benitocamela 10-13-2015 01:09 PM

output delay after crt.Screen.Send

Sometimes, after send a command with crt.Screen.Send "COMMAND" & chr(13), i'm wait for a specific string, ex: crt.Screen.WaitForString "RESULT".

But that specific string it's situated between another strings, this does sometimes the order crt.Screen.WaitForString
not read the string expected.

I guess this happens because the router send the outout very fast and the script can not read crt.Screen.WaitForString "RESULT"

is there any way to delay the output in secure.crt.


jdev 10-13-2015 01:33 PM

If you haven't done so already, I'd suggest you spend some time reading through the scripting guide.

Even if you're not using VBScript as your SecureCRT automation language, the concepts described in chapters 4 and 5 can be helpful for understanding concepts like "synchronous".

In general, you'll want to make sure that at the top of your script (or immediately following any Connect...() calls), you set the Screen object's "Synchronous" property to true, which will make sure that data doesn't get displayed to the screen before you make any calls designed to wait for or capture the data.

In your specific case, it would be helpful to know more details about the situation in which the problem occurs, so that a specific suggestion can be made towards a resolution.

Can you provide the specific text you're seeing, what you're waiting for and how, specifically, your script is failing?


benitocamela 10-14-2015 12:33 PM

Hi Jack

Im set the Screen object's "Synchronous" property to true, you can see it in the script:


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

Const ForReading = 1
Const ForWriting = 2

Sub Main

Dim logfile
logfile = "C:\TEMP\mysession.log"
crt.Session.LogFileName = logfile

Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")
'crt.Session.Log true
' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
Set file = fso.OpenTextFile("C:\MY_ROUTERS.txt", ForReading, False)
crt.Screen.Synchronous = True

Do while file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
crt.Screen.Send str & VbCr
crt.sleep 1000

crt.Screen.WaitForString "assword:",2
' Send your password followed by a carriage return
crt.Screen.Send "My_PASSWORD" & VbCr

crt.Screen.WaitForString ">"
crt.Screen.Send "COMMAND_1" & VbCr
crt.Screen.WaitForString ">"

crt.Screen.Send "CHECK_STATUS" & VbCr

nTimeout = 5
Do While crt.Screen.WaitForString ("busy", nTimeout)
crt.sleep 60000
crt.Screen.Send "CHECK_STATUS" & VbCr
crt.Screen.Send VbCr
crt.Screen.WaitForStrings ">"
crt.Screen.Send "exit" & VbCr

crt.Screen.WaitForString "~]$"


End sub
When i send crt.Screen.Send "CHECK_STATUS" & VbCr, im wait the word busy to start the loop until the router status is different than busy.

Text format where the word is busy after send the check status command, is:


CPU: 0.05% < 50% [OK]

Router resources are busy


jdev 10-14-2015 06:01 PM

The risk I see with your code is that you're waiting for "busy", but you're also passing in a timeout parameter of 5 seconds.

Is there ever a time where you won't see "busy" within 5 seconds of issuing the check-status command? If so, you'll need to up your timeout to accommodate the worst of cases.

Another approach would be to wait for more than one string, one for the failure (busy) case, and another for the success case.

If the device is not "busy", what shows up in the output of the command instead? In other words, is there something you see on the screen that tells you it's *not* busy as a result of running the check-status command? If so, then you can tell SecureCRT to wait for multiple strings, and tell you which one it found, so you can branch on that data to either exit your loop or continue waiting, or call your Aunt Sandra, or whatever you desire :).

For the sake of example let's say that your router says "Router ready" instead of "Router resources are busy" when it's, well, ready instead of busy. Your loop would look like this instead (throwing in a little bit of extra cool-ness in there for fun :)):


nTimeOut = 5
nSleepTime = 60
    nResult = crt.Screen.WaitForStrings("busy", "ready", nTimeOut)
    Select Case crt.Screen.MatchIndex
        Case 1
            For nCounter = 0 to nSleepTime - 1
                crt.Session.SetStatusText "Found 'busy'; Sleeping for " & nSleepTime - nCounter & " seconds..."
                crt.sleep 1000
            crt.Screen.Send "CHECK_STATUS" & VbCr
            crt.Screen.WaitForString "CHECK_STATUS"
        Case 2
            ' Ah! found "ready"; time to exit the loop
            crt.Session.SetStatusText "Found 'ready'; exiting loop"
            Exit Do
        Case 0
            ' In this case, we timed out...
            crt.Session.SetStatusText "Timed out waiting for strings."
            crt.Dialog.MessageBox "Timed out after " & _
                nTimeOut & " seconds." & vbcrlf & _
                "You will want to increase your time out, or add " & _
                "additional strings to look for."
            Exit Do
        Case Else
            ' In this case, you have a mismatch between the number of
            ' strings you're passing to WaitForStrings(), and the number
            ' of case statements you've written code to handle. Ooops.
            ' Time to write another case statement!
            crt.Dialog.MessageBox _
                "Oops! Time to write another case statement for string #" & _
            Exit Do
    End Select


All times are GMT -6. The time now is 02:09 PM.