VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Waitforstring doesn't work (https://forums.vandyke.com/showthread.php?t=14198)

js11o9 06-02-2020 01:43 AM

Waitforstring doesn't work
 
Code:

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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
        crt.Screen.Send "show run | grep hostname" & chr(13)
        crt.Sleep 100
        dd = crt.Screen.CurrentRow
        crt.Sleep 100
        dd2 = crt.Screen.get(dd,1,dd,50)
        dim result
               
        host_name = trim(dd2)
        crt.Screen.Send host_name & chr(13)
        crt.Sleep 100

        crt.Screen.Send "Show clock" & chr(13)
        result = crt.Screen.WaitForString (host_name)
       
        crt.Screen.Send "ter monitor" & chr(13)
        result = crt.Screen.WaitForString (host_name)
        'host_name

        crt.Screen.Send "Show tech | no" & chr(13)

        result = crt.Screen.WaitForString (host_name)
       
        crt.Screen.Send chr(13)
        result = crt.Screen.WaitForString (host_name)
        crt.Screen.Send "Show env | no" & chr(13)
       
End Sub

I have a problem with above script
waitforstring does not work until the command "show tech | no"
so next command "show env | no " does not work too

cboyack 06-02-2020 09:26 AM

Quote:

Originally Posted by js11o9 (Post 53624)
I have a problem with above script
waitforstring does not work until the command "show tech | no"
so next command "show env | no " does not work too

WaitForString is working exactly as it's supposed to in this scenario.

One important thing to note with regards to crt.Screen.Synchronous = True is that you must keep the crt.Screen.WaitForString statements consistent with the number of times that crt.Screen.Send is called.

With your script, the first crt.Screen.WaitForString refers back to the "show run | grep hostname" command instead of the "Show clock" command that the first WaitForString is intended to focus on. The end result is that your existing script code has 3 Screen.Send statements before the first WaitForString call is made.

In general, the best practice for fixing such issues is to call crt.Screen.WaitForString after EVERY crt.Screen.Send.

Additional synchronization can be achieved by waiting for each command itself in addition to its corresponding shell prompt. For example:

Code:

strcmd = "Show clock"
crt.Screen.Send strCmd & vbcr
crt.Screen.WaitForString strCmd
crt.Screen.WaitForString strShellPrompt



All times are GMT -6. The time now is 09:33 AM.