-1

我有以下 vbscript 命令:

crt.Screen.Send "cat myfile.txt | grep 'L[0-9]*' " &  vbcr

我想知道是否有办法知道命令是否输出任何内容,我需要在 vbscript 中进行

4

1 回答 1

1

从我从您发布的有限示例中收集到的信息来看,您似乎正在使用VanDyke Software 的 SecureCRT产品,该产品支持使用脚本自动执行任务。

在软件供应商网站上可以找到相当详细的Scripting Essentials Guide 。

在指南中详细介绍了如何从远程机器捕获数据(参见指南中的 4.3)

来自Scripting Essentials:在 SecureCRT 中使用 VBScript 的指南
以下与 Screen 对象关联的方法可用于通过与远程计算机的连接来捕获数据:ReadString()Get()Get2()。尽管 SecureCRT 的日志记录功能也可用于从远程设备捕获数据,但在后面的章节(使用 FileSystemObject 将数据写入文件)中会引用和讨论日志记录 API。如果您正在寻找访问当前在 SecureCRT 终端屏幕中选择的数据的方法,请参阅前面的部分,访问屏幕上的选定文本。

您可能还会发现这篇文章很有用,它解释了ReadString()工作原理,并举例说明了如何使用它将命令输出捕获到变量中。

该指南提供了一个基本示例,说明如何使用ReadString()从 Cisco 设备检索序列号。

crt.Screen.Synchronous = True
' Send a command to a Cisco device to get the serial number
' of the device.
crt.Screen.Send "sh tech-support | in ([sS]erial)" & vbcr
' Wait for the CR to be echoed back to us so that what is
' read from the remote is only the output of the command
' we issued (rather than including the command issued along
' with the output).
crt.Screen.WaitForString vbcr
' Capture the result into a script variable
strResult = crt.Screen.ReadString("pixfirewall#")
' strResult will contain something like:
' Serial Number: 1850889413810201 (0x6935FC6075819)
MsgBox strResult

您应该能够对其进行修改以满足您的要求。

该示例的前提是,一旦发送命令并返回回车符(Linux 上的Enter键)(表示命令已运行),它就会使用它ReadString()来捕获输出,但只有在它检测pixfirewall#到终端窗口。

于 2016-04-14T08:47:03.953 回答