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 01-26-2021, 11:12 AM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 95
Nothing shows on screen or in "MENU_SELECT_ALL"

I have created from scratch, an interactive method to use Excel to start an AdHoc SecureCRT Session, and have that session loop until an input condition is met.

The general idea:

Just before I start the SecurCRT session from Excel, the app sets an Environment variable to 'START', creates a TMP file, then starts the session with a script on the command line.

SecureCRT starts, hits a loop in the script, then waits for that environment variable to change to "RUN".

Excel is waiting for me to put a device command into a text box, then click a button. (this is only for a manual test, as ultimately, my app will build a list of commands to send).

When I click 'Send' in my app, this loads the command into the waiting TMP file, then sets the environment variable to 'RUN'.
The loop in SecureCRT sees that variable change, opens the file and sends the line in the file. (For now, this is one line, but eventually will be several lines.)

When 'RUN' is detected, it clears the screen and scrollback, sends a vbCr, then the command, then does a WaitForString to get the device prompt.

The Log File shows all this activity, but when I do: crt.Screen.SendSpecial("MENU_SELECT_ALL") followed by strBufferText = crt.Screen.Selection - the variable is empty (as well as the screen is blank).

My intention is to write the screen contents back to the TMP file, then set the environment variable to something that Excel is looping on to then read that file and process the result.

Since the variable is empty, it dies.

Here is the relevant VB from SecureCRT:

Code:
crt.Session.Log False            
Set objTab = crt.GetScriptTab
objTab.Screen.Synchronous = True

...

intLoopCount = 0
objTab.Session.LogFileName =  UserProf & "\SecureCRT Logs\" & UserName & "\%Y-%M-%D.%h.%m - " & strShortHostName & " -- (" & UserName & ").log"
objTab.Session.Config.SetOption "Custom Log Message Each Line", "%h:%m:%s | "
objTab.Session.LogUsingSessionOptions
Set fso = CreateObject("Scripting.FileSystemObject")
Set envUser = shell.Environment("USER")
strSemaphore = envUser("SecureCRTStatus") ' This is set by external Application
strPrompt1 = Trim(crt.Screen.Get(crt.Screen.CurrentRow, 0, crt.Screen.CurrentRow, crt.Screen.CurrentColumn))
objTab.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
objTab.Screen.Send vbCr
crt.Sleep(250)
Do
    Do
        strSemaphore = envUser("SecureCRTStatus")                  ' This is set by external Application
        Select Case strSemaphore
            Case "HALT"
                Exit Do ' Exit Inner DO
            Case Else
                crt.Session.SetStatusText("Waiting for Run : " & strSemaphore & " : " & intLoopCount)
                crt.Sleep(1000)                                        ' 1 Sec pause for sanity
                intLoopCount = intLoopCount + 1
        End Select
    Loop Until strSemaphore = "RUN"                          ' External app Signals with "RUN"
    intLoopCount = 0
    Set fsoIOFilePathName = fso.OpenTextFile(strCommandARG2, ForReading)
    Do Until fsoIOFilePathName.AtEndOfStream
        strInputLine = fsoIOFilePathName.ReadLine          ' Read each line for command(s)
        If strInputLine = "" Then Exit Do                 ' All done
        objTab.Screen.Send strInputLine & vbCr             ' Send the line
        objTab.Screen.WaitForString strPrompt1, 300        ' Wait for prompt (long delay)
    Loop
    fsoIOFilePathName.Close
    Set fsoIOFilePathName = fso.OpenTextFile(strCommandARG2, ForWriting, True)
    crt.Screen.SendSpecial("MENU_SELECT_ALL")
    strBufferText = crt.Screen.Selection ' <<<-- NOTHING IS COPIED HERE
    Select Case strBufferText
        Case ""
            strBufferText = "NOTHING RETURNED"
    End Select
    crt.Dialog.MessageBox strBufferText
    fsoIOFilePathName.Write strBufferText
    fsoIOFilePathName.Close
    crt.Sleep(1000)                                        ' 1 Sec pause for sanity
    envUser("SecureCRTStatus") = "COMPLETE"                    ' Let External app know we are done
Loop Until strSemaphore = "HALT"                           ' External app may send HALT to kill this loop
Any input will be helpful.
Reply With Quote
  #2  
Old 01-27-2021, 12:10 PM
Rhudi's Avatar
Rhudi Rhudi is offline
Registered User
 
Join Date: Jul 2013
Location: Greenville, SC
Posts: 95
I have messed with this for a while now, and have concluded that I just don't understand how 'WaitForString' works.
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 08:21 PM.