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 02-25-2021, 10:26 PM
FabriceCarboni FabriceCarboni is offline
Registered User
 
Join Date: Feb 2021
Location: Belgium
Posts: 10
crt.Screen.WaitForStrings Python

Hello,


I am writing a script in Python that allows me to delete a file on a switch.
To that I need to wait for a string to appear on the screen of my console.
I'm Using the instruction crt.Screen.WaitForStrings but it dosen't work.


Can you help me?


That's my code

Code:
# $language = "python"
# $interface = "1.0"

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


def pause():

  import time
  time.sleep(1)

pause()

def reload():

    crt.Screen.Synchronous = True
    crt.Screen.Send("reload" + chr(13))
    crt.Screen.Send("y")
reload()

def MiniBoot():
    crt.Screen.WaitForStrings("#Press s to STOP AT MINIBOOT...")
    crt.Screen.Send("s")
MiniBoot()

Last edited by jdev; 02-26-2021 at 08:46 AM. Reason: Please wrap code with a [CODE] tag at the beginning and a [/CODE] tag at the end.
Reply With Quote
  #2  
Old 02-26-2021, 01:55 AM
FabriceCarboni FabriceCarboni is offline
Registered User
 
Join Date: Feb 2021
Location: Belgium
Posts: 10
crt.Screen.WaitForStrings

Hello,

I'm Curently writting a script in Python to remove Users on Alcatel Switch
To do that I need to reload the switch and start it in miniboot.
To start the switch in miniboot I need to press S when the message "Press s to STOP AT MINIBOOT..." apear on my console screen.
Then I wrote that code and it dosen't work, the S is not send it seem's
Is someone can help me please?

Code:
def reload():

    crt.Screen.Synchronous = True
    crt.Screen.Send("reload" + chr(13))
    crt.Screen.Send("y")
reload()

def MiniBoot():
    crt.Screen.Synchronous = True
    a = "Press s to STOP AT MINIBOOT..."
    vWaitForStrings = crt.Screen.WaitForStrings(a)
    if vWaitForStrings == a:
         crt.Screen.Send("s")
MiniBoot()

Last edited by jdev; 02-26-2021 at 08:46 AM. Reason: Please wrap code with a [CODE] tag at the beginning and a [/CODE] tag at the end.
Reply With Quote
  #3  
Old 02-26-2021, 09:03 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,091
Dear FabriceCarboni,

If your script isn't working like you expect, the first place to go would be this post:
FAQ: Why doesn't my SecureCRT script work like I need it to?
Read through the information in that post, and adjust your script accordingly.

Additional notes include:
  • crt.Sleep() is a method documented in SecureCRT's built-in help. It pauses script execution for the specified number of milliseconds.
  • In Python, the statement crt.Screen.Send("reload" + chr(13)) can also be represented like this: crt.Screen.Send("reload\r")
  • crt.Screen.WaitForStrings() does not return a string value. So your comparison statement: if vWaitForStrings == a: ... is entirely bogus and won't ever be true.
  • crt.Screen.WaitForStrings() takes as its parameter an array of strings. You're only passing in one single string value. You should be using crt.Screen.WaitForString() instead of WaitForStrings() in this scenario because you're only waiting for one single string value to be found.
  • crt.Screen.WaitForString(a) won't return until the string value in variable 'a' is found. In which case there's no need for you to do any if... statement. Just send the "s" as needed.

Read through the guide I linked to earlier, and make the needed adjustments to your script.

If you require additional assistance, please provide more information about what is showing up on your screen from start to finish as your script is running, and include any error messages you might be seeing as a result of any python language syntax errors, etc.

--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


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 02:18 AM.