This method is only available in COM version
of the component.
Execute method will send command of your choice to the
server, and wait until it is completed. If it does not
return in specified time, timeout error is generated.
There's no general way of knowing what to expect
from command to return once you execute it, so you must use
Prompt argument to specify what to
expect to be received after last line of the command. Most
usually, this will be your command prompt, but depending on
the command you execute, it can be something else -
meaningful to you.
NOTE: this method works only when Blocking
property is set to True.
Common way for using Execute method is to send few
commands sequentially, waiting for each to return something
and probably make a decision on what to do next. Without
usage of Execute method, you would need some complicated
algorithms - so Execute comes here to help. Don't
forget to put CRLF (vbCrLf) sequence at the end of your
command, since wodTelnetDLX will not do that for you (we
never know if you actually want it).
Typically, you might want to use it like this:
TelnetDLX1.Blocking = True
TelnetDLX1.Connect
Debug.Print
TelnetDLX1.WaitFor("joe@debian")
TelnetDLX1.Prompt = "joe@debian"
Debug.Print
TelnetDLX1.Execute("cd
/tmp" & vbCrLf)
Debug.Print
TelnetDLX1.Execute("ls
-al" & vbCrLf)
and it will do the following - connect to the server,
wait everything until prompt is received (I assume here
that joe@debian is prompt that is
expected to be received), and then change directory to
/tmp and list all files.
Good thing is that if Execute method fails, you will
still be able to Receive
complete data arrived in the meantime, Received
event will be fired to notify you to do that, just to let
you know why it failed.
Since version 2.0.0.2, Timeout can be specified as
negative value. When set up this way, wodTelnetDLX will use
it as 'absolute timeout' - component will return
from Execute method call in specified time no matter if it
was idle or busy in that time. This change was made to
prevent wodTelnetDLX from freezing if expected response is
never received. wodTelnetDLX.Timeout
property will still hold regular, 'inactivity
timeout' value as it was before. One sidenote - it is
almost impossible to predict what state of the session will
be when this 'absolute timeout' expires. You may
still receive big amount of data that will confuse your
client, depending on what was going on while Execute method
was running.
Note - this command internally disables PromptReceived
event and Received
event since it's taking control on what's received
from the server.
You can also provide regular expression to be searched in
received data instead of exact value. You should prepend your
Execute argument with regex: text so wodTelnetDLX knows you are using
regular expression. For example, you can use it like this:
- Debug.Print
Telnet1.Execute("cd /tmp"
& VbLf, "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 Telnet1.Execute("cd /tmp" &
VbLf, "regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9-/]+[\$%#>] $")
or using extended PERL syntax
Debug.Print Telnet1.Execute("cd /tmp" &
VbLf, "regex:\w+@\w+:\S+\$ $")
just don't forget to put 'regex:' text in front of regular
expression, otherwise wodTelnetDLX will search for exact match of
specified pattern. PCRE (www.pcre.org)
library is used for regex support.