VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   VBScript how to ignore Case with Screen.WaitForString (https://forums.vandyke.com/showthread.php?t=13473)

Reno 03-28-2019 11:47 AM

VBScript how to ignore Case with Screen.WaitForString
 
I'm working on a script that (in a loop) SSH's into multiple VM's. I've noticed that randomly (or with certain VM's) the prompt indicating the VM name may be upper case or lower case.

Example: With the inserted text from the array, I need to make the inserted array value case insensitive like where you would UCase two strings to compare them in a case insensitive way.

crt.Screen.WaitForString "[root@" & my_array(x,1) & "admin]# "

Thanks!

berdmann 03-28-2019 01:26 PM

Hi Reno,

Please refer to the following example:

Code:

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

Do
    strHostPrompt = "[root@myhostnameadmin]#"
    ' We're calling a wrapper function we created to make
    ' it easier to do case-insensitive waits
    WaitForStringCI strHostPrompt
    MsgBox "We found it... moving on..."
Loop

Function WaitForStringCI(strData)
    ' This is a wrapper function that makes case-insensitive
    ' calls to WaitForString much easier...
    '
    ' We're calling WaitForString with the bCaseInsensitive
    ' True|False flag which requires a timeout param. Since
    ' we don't really want this to time out, we'll use an
    ' exceptionally large number of seconds (approximately 7.6
    ' days)
    WaitForStringCI = _
        crt.Screen.WaitForString(strData, (65535 * 10), True)
End Function


Reno 03-28-2019 02:52 PM

Thank you, that worked perfectly.

Now I'm trying to figure out how to have it loop for only (say) 15 seconds before giving up and exiting with an error message. :)

berdmann 03-28-2019 05:13 PM

Hi Reno,

Is this what you are trying to do?

Code:

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

Do
    strHostPrompt = "[root@myhostnameadmin]#"
    ' We're calling a wrapper function we created to make
    ' it easier to do case-insensitive waits
    nTimeOut = 15
    If Not WaitForStringCI(strHostPrompt, nTimeout) Then
        MsgBox "Failed to find """ & strHostPrompt & """ within " & nTimeOut & " seconds."
        Exit Do
    Else
        MsgBox "We found it... moving on... (looping again for a look-see)"
    End If
Loop

Function WaitForStringCI(strData, nTimeout)
    ' This is a wrapper function that makes case-insensitive
    ' calls to WaitForString much easier...
    '
    ' We're calling WaitForString with the bCaseInsensitive
    ' True|False flag which requires a timeout param. Since
    ' we don't really want this to time out, we'll use an
    ' exceptionally large number of seconds (approximately 7.6
    ' days)
    WaitForStringCI = _
        crt.Screen.WaitForString(strData, nTimeout, True)
End Function



All times are GMT -6. The time now is 12:59 PM.