-1

I have the following vbscript command:

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

I want to know if there is a way to know if the command outputs anything or not, I need to do it in vbscript

user692942
  • 16,398
  • 7
  • 76
  • 175
Anne Ortiz
  • 133
  • 1
  • 1
  • 5
  • Without knowing what the `crt` object is we can't help you. There should be a `Set crt = CreateObject("...")` further up in the code somewhere that defines what crt is or a `Set crt = new ...` if it's a VBScript class. – user692942 Apr 14 '16 at 07:25

1 Answers1

1

From what I can gather from the limited example you have posted it looks as though you are using VanDyke Software's SecureCRT product which supports automation of tasks using scripting.

There is quite a detail Scripting Essentials Guide found on the software providers website.

In the guide it details how to capture data from a remote machine (see 4.3 in the guide)

From Scripting Essentials: A Guide to Using VBScript in SecureCRT
The following methods associated with the Screen object can be used to capture data via a connection to a remote machine: ReadString(), Get(), and Get2(). Although SecureCRT's logging capabilities can also be used to capture data from a remote device, the logging API is referenced and discussed in a later chapter (Writing Data to Files Using the FileSystemObject). If you're looking for ways to access data that is currently selected within the SecureCRT terminal screen, please see the earlier section, Accessing Selected Text on the Screen.

You may also find this article useful which explains how ReadString() works and gives an example of how to use it to capture command output into a variable.

The guide gives a basic of example of how using ReadString() works to retrieve a serial number from a Cisco device.

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

Which you should be able to modify to fit your requirement.

The example works on the premise that once the command is sent and the Carriage Return character (Enter key in affect on Linux) returned (to denote the command has run) it then uses ReadString() to capture the output but only once it detects the prompt pixfirewall# in the terminal window.

user692942
  • 16,398
  • 7
  • 76
  • 175