【问题标题】:SecureCRT: VBScript printing output to consoleSecureCRT:VBScript 打印输出到控制台
【发布时间】:2016-05-05 23:38:03
【问题描述】:

我已经编写了脚本来使用安全 crt 从我的本地计算机连接到 Jump 服务器。我能够执行脚本并将输出捕获到 Msgbox,但无法将其打印到控制台。

下面是我写的代码。

    #$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
'========================================

我正在将脚本输出捕获到 szData 变量中。有没有办法在控制台中打印相同的内容?

【问题讨论】:

    标签: vbscript secure-crt


    【解决方案1】:

    您已经在使用该命令

    crt.Screen.Send
    

    您只需要传递一个将输出到控制台的有效命令,如果在 Windows Server 上执行此操作,您应该能够使用命令行程序ECHO 来输出到控制台。

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

    输出(未经测试,但应该产生)

    Display in console!!!
    

    所以你应该能够做到

    crt.Screen.Send "echo " & szData
    

    有用的链接

    【讨论】:

    • 谢谢兰基玛特! .但问题是,我正在从 Windows 桌面运行 VB 脚本并执行 RHEL Jump 服务器中存在的 linux shell 脚本,我希望将 linux scipt 的输出打印在 Windows 命令提示符中。这样我就可以解析输出了。
    • @Praneeth 嗯,这在原始问题中会有很多有用的信息。你不提我怎么知道?
    • @Praneeth 您正在执行 Linux Shell 脚本究竟是什么,也许是 Windows 命令提示符?
    • 真的很抱歉.. 是的,我正在从 Windows 命令提示符命令运行脚本:"C:\Users\praneeth\Desktop\secureCRT\Test&gt;securecrt.exe /SCRIPT "C:\Users\praneeth\Desktop\secureCRT\Test\oswatch_drv.vbs" /ARG "ls -l" /S "linuxpv0002.intl.com"
    • 我尝试使用 Wscript.Echo 打印变量的内容。但它不起作用。
    猜你喜欢
    • 2021-12-13
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多