Back to product page

WaitFor method


Waits and reads data until a specific pattern is found.

Type

A String value. Holds data received in WaitFor method.

Syntax

  • Basic
object.WaitFor (Pattern, [Timeout])
The WaitFor(object,Pattern,Timeout) syntax has these parts:
objectAn expression evaluating to an object of type wodSSH.
PatternRequired. A String value. The prompt that we expect to receive - which indicates the end of execution. (exact text or regular expression)
TimeoutOptional. A Variant value. The number of seconds of inactivity to allow for completion.

Remarks

The WaitFor method will wait and receive data from the server until the specified Pattern is found or the timeout expires. If timeout is not specified, then the value defined in Timeout property is used as a default. If timeout expires, you will get an error, but you will still be able to receive data that arrived in the meantime using Receive method call.

NOTE: this method works only when the Blocking property is set to True.

A very common way to use the WaitFor method is to read all data that the server sends upon connection. Usually you will know exactly what you need to receive and so you can use this command to help you, for example:
 
   Ssh1.HostName = "yourhost"
   Ssh1.Login = "tester"
   Ssh1.Password = "weonlydo"
   Ssh1.Protocol = SSHAuto
   Ssh1.Blocking = True
   Ssh1.Connect
   Debug.Print Ssh1.WaitFor("joe@debian")
 

This sample will block until 'joe@debian' is found within the received text. If it is not found before the timeout expires you will still be able to Receive the last 16k of data so that you can check why it failed.

Note - this command internally disables the PromptReceived and Received events because it takes control of what is received from the server.

As mentioned above, you can provide regular expression to be set as expected response. You should prepend Pattern argument with regex: text so wodSSH knows you are using regular expression. For example, you can use it like this:

Debug.Print Ssh1.WaitFor("regex:[\$%#>] $")

above regular expression will match when:
  • $, %, #, or > found
  • space
  • end of line
typically, our previous sample joe@somehost:-$<SPACE> does match above regex. But, hey, feel free to use something more complex such as:

     Debug.Print Ssh1.Execute("cd /tmp" & VbLf, "regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9-/]+[\$%#>] $")

     or using extended PERL syntax

     Debug.Print Ssh1.Execute("cd /tmp" & VbLf, "regex:\w+@\w+:\S+\$ $")

just don't forget to put 'regex:' text in front of regular expression, otherwise wodSSH will search for exact match of specified pattern. PCRE (www.pcre.org) library is used for regex support.

Platforms

Windows