我已经编写了脚本,使用安全的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
'========================================我正在将脚本输出捕获到szData变量中。有办法在控制台中打印相同的内容吗?
发布于 2016-05-05 15:38:03
您已经在使用以下命令
crt.Screen.Send您只需要传递一个有效的命令,该命令将输出到控制台,如果在Windows上这样做,您应该能够使用命令行程序ECHO输出到控制台。
crt.Screen.Send "echo Display in console!!!"输出(未经测试,但应产生)
Display in console!!!所以你应该能做到
crt.Screen.Send "echo " & szData有用的链接
https://stackoverflow.com/questions/37054221
复制相似问题