Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-13-2018, 10:39 AM
Hang Hang is offline
Registered User
 
Join Date: Jul 2016
Posts: 21
Post scripting hanging at if waitforstring statement

I was wondering if you guys have a suggestion for a better way of cycling through password.

My current script always hang at the if statement.

Here is my code:
Code:
prompt = "A:"
currentTab = crt.GetScriptTab()
password = ["wrongPass", "rightPass"]


def main():		
	x = 0
	currentTab.Screen.Synchronous = True		
	currentTab.Screen.Send("kernel\r")
	while currentTab.Screen.WaitForString("assword:") == True:
		currentTab.Screen.Send(password[x]+"\r")
		if currentTab.Screen.WaitForString(prompt) == True:			
			x = x + 1		
			currentTab.Screen.Send("kernel\r")	
		else:
			break

	currentTab.Screen.Send("finished")
	
main()
Here is my output:
Quote:
*A:# kernel
Password:
MINOR: CLI Unidentified command.
*A:# kernel
Password:
Type "exit" to return to CLI.
1->
As you can see the right password was enter on the second try. However, the script will hang at the waitforstring(prompt) line of code and never send the "finished" string. It is waiting for "A:" but we already log into the kernel and it doesn't go to the else statement to break out of the while loop.
Reply With Quote
  #2  
Old 02-13-2018, 12:05 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
WaitForString(), WaitForStrings(), and ReadString() only operate on data that has not yet been displayed to the Screen.

So, if something has already been displayed to the Screen, it's too late to try and branch on something else that you would then try and Wait for.

If you expect to branch script code on a number of different strings that could appear on the Screen, then you must use WaitForStrings(string1, string2, string3, ...) and then branch on the value of the Screen.MatchIndex property (which tells you the left-to-right index -- or top-to-bottom index, depending on how you've structured your code -- of the string that WaitForStrings() found.

This technique is demonstrated in the Jump Host - Handle Secondary Host Connection Attempts example script found in the script examples 'sticky'.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
Reply

Tags
if statement , waitforstring

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 08:05 PM.