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 06-02-2020, 01:43 AM
js11o9 js11o9 is offline
Registered User
 
Join Date: Jun 2020
Posts: 4
Exclamation 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

Last edited by jdev; 06-02-2020 at 07:16 AM. Reason: Please use [code][/code] tags around your code for preserving indentation/spacing
Reply With Quote
  #2  
Old 06-02-2020, 09:26 AM
cboyack cboyack is offline
VanDyke Technical Support
 
Join Date: Apr 2020
Location: Albuquerque, NM
Posts: 22
Quote:
Originally Posted by js11o9 View Post
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
__________________
Thanks,
--Cameron

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
wairforstring


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 01:47 PM.