View Single Post
Old 05-22-2017, 08:47 AM
thera34's Avatar
thera34 thera34 is offline
Registered User
Join Date: May 2015
Location: Romania
Posts: 8

Instead of waiting for your "# ", I prefer to read and store first the device's full prompt then after I issue a Screen.Send something, I just Screen.WaitForString for that prompt like in the below example.
The GetShellPrompt Function I found it somewhere on the internet (maybe in this exact forum, cannot remember).

#$language = "VBScript"
#$interface = "1.0"
Dim strPrompt
' some other stuff

Sub Main

		bCursorMoved = crt.Screen.WaitForCursor(1)														' I instruct SecureCRT to wait until cursor stops moving for 1 second (Can be increased for slower machines)
	Loop Until bCursorMoved = False
	strPrompt = GetShellPrompt()																		' Get Terminal Server's (or other devices) prompt

' Now some misc code
crt.Screen.Send "term length" & chr(13)
crt.Screen.WaitForString strPrompt
' and so on
End Sub

' -----------------------------------------------------------------------------
' GetShellPrompt - determine the shell's prompt
' -----------------------------------------------------------------------------
Function GetShellPrompt()
																				' Heuristically determine the shell's prompt.  Crt.Screen.Synchronous must
																				' already have been set to True.  In general, Crt.Screen.Synchronous should
																				' be set to True immediately after a successful crt.Session.Connect().  In
																				' This script, SecureCRT should already be connected -- otherwise, a script
																				' error will occur.
    Do																			' Simulate pressing "Enter" so the prompt appears again...
        crt.Screen.Send vbcr
																				' Attempt to detect the command prompt heuristically by waiting for the
																				' cursor to stop moving... (the timeout for WaitForCursor above might
																				' not be enough for slower- responding hosts, so you will need to adjust
																				' the timeout value above to meet your system's specific timing
																				' requirements).
            bCursorMoved = crt.Screen.WaitForCursor(1)
        Loop Until bCursorMoved = False
																				' Once the cursor has stopped moving for about a second, it's assumed
																				' it's safe to start interacting with the remote system. Get the shell
																				' prompt so that it's known what to look for when determining if the
																				' command is completed. Won't work if the prompt is dynamic (e.g.,
																				' changes according to current working folder, etc.)
        nRow = crt.Screen.CurrentRow
        strPrompt = crt.Screen.Get(nRow, 0, nRow, crt.Screen.CurrentColumn - 1)
																				' Loop until a line of non-whitespace text actually appears:
        strPrompt = Trim(strPrompt)
        If strPrompt <> "" Then Exit Do
    GetShellPrompt = strPrompt
End Function
Reply With Quote