SecureCRT:VBScript打印输出到控制台

SecureCRT:VBScript打印输出到控制台,vbscript,secure-crt,Vbscript,Secure Crt,我已经编写了使用安全crt从本地计算机连接到跳转服务器的脚本。我能够执行脚本并将输出捕获到Msgbox中,但无法将其打印到控制台 下面是我写的代码 #$language = "VBScript" #$interface = "1.0" Set objTab = crt.GetScriptTab Set g_shell = CreateObject("WScript.Shell") Public szData crt.Sleep 6000 objTab.Screen.Igno

我已经编写了使用安全crt从本地计算机连接到跳转服务器的脚本。我能够执行脚本并将输出捕获到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
'========================================
#$language=“VBScript”
#$interface=“1.0”
设置objTab=crt.GetScriptTab
Set g_shell=CreateObject(“WScript.shell”)
公共数据
睡眠6000
objTab.Screen.IgnoreEscape=True
objTab.Screen.Synchronous=True
Dim szCommand、szPrompt、nRow、szLogFileName、nIndex
做
bCursorMoved=objTab.Screen.WaitForCursor(1)
循环直到bCursorMoved=False
nRow=objTab.Screen.CurrentRow
szPrompt=objTab.screen.Get(nRow_
0, _
哦_
objTab.Screen.current列-1)
szPrompt=修剪(szPrompt)
crt.Screen.Synchronous=True
迪姆普兰
副总管
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=captureoutofcommand(“sh test.sh”[xyz@xlpv0002“~]”和vbCr**
'MsgBox(szData)
pran=szData
crt.Clipboard.Format=“CF\u TEXT”
crt.Clipboard.Text=pran
crt.Dialog.MessageBox(“文本现在在剪贴板中:\n\n”+crt.clipboard.Text)
'MessageBox.Show(szData)
如果不是SendExpect(“退出”)[xyz@xlpv0002然后退出sub
g_shell.Run“%comspec%/c taskkill/IM SecureCRT.exe/F”
端接头
'=======================================================================
函数captureoutofcommand(szCommand,szPrompt)
如果crt.Session.Connected为True,则
CaptureOutputOfCommand=“[错误:未连接。]”
退出功能
如果结束
objTab.Screen.Send命令和vbcr
objTab.Screen.WaitForString vbcr
captureoutofcommand=objTab.Screen.ReadString(szPrompt)
端函数
'======================================================================
函数SendExpect(szSend,szExpect)
如果objTab.Session.Connected为True,则退出函数
objTab.Screen.Send szSend和vbcr
objTab.Screen.WaitForString szExpect
SendExpect=True
端函数
'========================================

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

您已经在使用该命令了

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

crt.Screen.Send“控制台中的回声显示!!!”
输出(未测试,但应产生)

显示在控制台中!!!
所以你应该能做到

crt.Screen.Send“echo”和szData

有用的链接
  • (正式文件)

您已经在使用该命令

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

crt.Screen.Send“控制台中的回声显示!!!”
输出(未测试,但应产生)

显示在控制台中!!!
所以你应该能做到

crt.Screen.Send“echo”和szData

有用的链接
  • (正式文件)

谢谢你,兰克马特。但问题是,我正在windows桌面上运行VB脚本,并执行RHEL Jump server中的linux shell脚本,我希望linux scipt的输出打印在windows命令提示符中。这样我就可以分析输出了。@praneth好吧,这是很多在原始问题中有用的信息。如果你不提,我怎么知道呢?@praneth你是从什么地方执行Linux Shell脚本的,可能是Windows命令提示符?真的很抱歉。。是,我正在从windows命令提示符命令运行脚本:
“C:\Users\praneth\Desktop\secureCRT\Test>secureCRT.exe/script”C:\Users\praneth\Desktop\secureCRT\Test\oswatch\u drv.vbs”/ARG“ls-l”/S”linuxpv0002.intl.com“
我尝试使用Wscript.Echo打印变量的内容。但它不起作用。谢谢你,兰克马特。但问题是,我正在windows桌面上运行VB脚本,并执行RHEL Jump server中的linux shell脚本,我希望linux scipt的输出打印在windows命令提示符中。这样我就可以分析输出了。@praneth好吧,这是很多在原始问题中有用的信息。如果你不提,我怎么知道呢?@praneth你是从什么地方执行Linux Shell脚本的,可能是Windows命令提示符?真的很抱歉。。是的,我正在从windows命令提示符命令运行脚本:
“C:\Users\praneth\Desktop\secureCRT\Test>secureCRT.exe/script”C:\Users\praneth\Desktop\secureCRT\Test\oswatch\u drv.vbs”/ARG“ls-l”/S“linuxpv0002.intl.com”
我尝试使用Wscript.Echo打印变量的内容,但不起作用。