2

I have written script to connect from my local machine to Jump server using secure crt. i was able to execute the script and capture the output into Msgbox, But unable to print it to console.

Below is the code which i have written.

    #$language = "VBScript"
#$interface = "1.0"
Set objTab = crt.GetScriptTab
Set g_shell = CreateObject("WScript.Shell")

Public szData

crt.Sleep 6000

    objTab.Screen.IgnoreEscape = True
    objTab.Screen.Synchronous = True

    Dim szCommand, szPrompt, nRow, szLogFileName, nIndex

    Do
        bCursorMoved = objTab.Screen.WaitForCursor(1)
    Loop until bCursorMoved = False

    nRow = objTab.Screen.CurrentRow
    szPrompt = objTab.screen.Get(nRow, _
                                 0, _
                                 nRow, _
                                 objTab.Screen.CurrentColumn - 1)
    szPrompt = Trim(szPrompt)

crt.Screen.Synchronous = True

Dim pran

Sub Main

    strVal = crt.Arguments(0)

    crt.Screen.Send "pwd" & chr(13)
    crt.Screen.WaitForString "[xyz@xlpv0002 ~]$"
    crt.Screen.Send "sh test.sh" & chr(9) & chr(13)

    **szData = CaptureOutputOfCommand("sh test.sh", "[xyz@xlpv0002 ~]")  & vbCr**   
    'MsgBox(szData)
    pran = szData

    crt.Clipboard.Format = "CF_TEXT"
    crt.Clipboard.Text = pran

    crt.Dialog.MessageBox("Text is now in the clipboard: \n\n" + crt.Clipboard.Text)
    'MessageBox.Show(szData)

    If Not SendExpect("exit", "[xyz@xlpv0002 ~]") then exit sub

    g_shell.Run "%comspec% /c taskkill /IM SecureCRT.exe /F"

End Sub

'=======================================================================
Function CaptureOutputOfCommand(szCommand, szPrompt)
    if crt.Session.Connected <> True then
        CaptureOutputOfCommand = "[ERROR: Not Connected.]"
        exit function
    end if

    objTab.Screen.Send szCommand & vbcr
    objTab.Screen.WaitForString vbcr
    CaptureOutputOfCommand = objTab.Screen.ReadString(szPrompt)

End Function
'======================================================================
Function SendExpect(szSend, szExpect)
    if objTab.Session.Connected <> True then exit function

    objTab.Screen.Send szSend & vbcr
    objTab.Screen.WaitForString szExpect

    SendExpect = True
End Function
'========================================

I am capturing the script output into szData variable. Is there a way to print the same in the console?

Fla-Hyd
  • 279
  • 7
  • 17

1 Answers1

0

You are already using the command

crt.Screen.Send

You just need to pass a valid command that will output to the console, if doing this on a Windows Server you should be able to use the Command Line program ECHO to output to the console.

crt.Screen.Send "echo Display in console!!!"

Output (untested, but should produce)

Display in console!!!

So you should just be able to do

crt.Screen.Send "echo " & szData

Useful Links

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • Thank you Lankymart ! . But problem is, i am running VB script from windows desktop and executing a linux shell script present in RHEL Jump server, i want the output of the linux scipt to be printed in the windows command prompt. so that i can parse the output. – Fla-Hyd May 05 '16 at 15:47
  • @Praneeth Well that's a lot of information that would have been useful in the original question. How am I supposed to know that if you don't mention it? – user692942 May 05 '16 at 15:49
  • @Praneeth You're executing the Linux Shell script from what exactly, the Windows Command Prompt perhaps? – user692942 May 05 '16 at 15:51
  • Really sorry for that.. yes i am running the script from windows command prompt Command : `"C:\Users\praneeth\Desktop\secureCRT\Test>securecrt.exe /SCRIPT "C:\Users\praneeth\Desktop\secureCRT\Test\oswatch_drv.vbs" /ARG "ls -l" /S "linuxpv0002.intl.com"` – Fla-Hyd May 05 '16 at 15:53
  • i tried using Wscript.Echo to print the contents of the variable. But it is not working. – Fla-Hyd May 05 '16 at 16:04
  • @Praneeth when you say it's not working, in what way? Does it error, if so what is the error. Does in just not print out anything? or does it print out something your not expecting? – user692942 May 05 '16 at 17:07