My english isn't good that's why I decribe this for example
1. I connect with one computer e.g. by telnet
2. I'm staring to read his statistics or logs not important
3. Then I connect with another computer without ending first connect
4. Afer that I sending to second computer so command and I'm watching
action on the first machine.
Do you have so idea what it could make?
I know that in expect you can "spawn" many programs but I haven't found
someting valuable which describe something similar like it.
Sincerely Sebastan
You "spawn" a connection to each computer via some program such as telnet..
Each spawn produces a unique spawn_id. Use the appropriate spawn ID to
send and expect from each computer.
Sincerely Sebastian
On Mon, 12 Sep 2005, ms wrote:
> Earl Grieda napisa?(a):
When you spawn a process expect will return an identifier
for the spawned process in a variable (spawn_id) in the current scope.
This variable in then used for sending or receiving fromthe process.
You should saved this identifier after each spawn command
and then set spawn_id to the identifier of the process
you want to deal with.
for example:
spawn the_process_1 ; # spawn the first process
set spawn_id_1 $spawn_id ; # save the id of the first process
spawn the_process_2 ; # spawn the second process
set spawn_id_2 $spawn_id ; # save the id of the second process
#
# select the first process to interact with
#
set spawn_id $spawn_id_1
exp_send "send some data\r"
expect { ... }
#
# Select the second process to interact with
#
set spawn_id $spawn_id_2
exp_send "something\r"
expect { ... }
Most of the expect command have a -i option which allows
to give the spawned process identifier as argument
instead of relying on the content of the spawn_id value.
------------------------------
David Bariod
For email replace spam by tel
Sincerely
Sebastian
On Mon, 12 Sep 2005, ms wrote:
> dba...@norspam.com napisał(a):
There is a buffer for each spawned process.
The expect command is blocking.
Whatever the order in which you receive the data
each buffer will be filled.
But there is a timeout set for the expect command to return
according to the content of the timeout variable from the caller scope.
ex:
#
# The expect will not block the caller
# If no pattern match the data the command will return
# immediatly.
#
set timeout 0 ; # the expect will not block the
#
# The command block indefinitely until one pattern
# is matched.
#
set timeout -1
#
# The command will wait for data at most for 30 seconds
#
set timeout 30
You can tune the timeout value according to your case.
If there is some kind of relation between the two output and/or
acion must be triggered on a spawned process to have a given
output from the other one, you can also use a single expect command
waiting on several spawed process with an appropriate exp_continue command
within the associated action to reach the wanted behaviour.
The code snippet below will perform a single expect command
waiting on two stream for a dedicated pattern for each
spawned process.
The expect command will return when the two will have been received
or on timeout condition.
set pattern_1_received 0
set pattern_2_received 0
expect {
-i $spawn_id_1 "Your pattern 1" {
set pattern_1_received 1
if {0 == $pattern_2_received} {
exp_continue
}
#
# Do the needed action
#
}
-i $spawn_id_2 "Your pattern 2" {
set pattern_2_received 1
if {0 == $pattern_2_received} {
exp_continue
}
#
# Do the needed action
#
Thanks
Avnish
> Hi David,
> Just wanted to confirm if there's any dependency on Expect version for
> above block to work?
It should not have any dependency related to the expect version.
> If am correct this block will work with 5.42
> onward as Non blocking IO channels were introduced in this version
> itself.
>
Sorry, but I have no idea about the impact of
"the non blocking IO channels introduction".
I guess it's just a change in the implementation
and should not have any impact on the expect commands
behaviour (except the higher cpu load features ;-))
Can some expect expert confirm this ?
Thanks for your example, one more time :)
Sincerely Sebastan
> Thx for example. It looks as able to solve my problem. But I wonder is
> exist any different way for get this. I mean this code is ok but my
> one's from expects is very complex and when I use this way of coding
> all of it will be unreadable. Could I use any shortcut e.g. proc or
> source? I don't now maybe there is something else?
>
Well, it depends if you really need to simultaneously send commands
and then simultaneously wait for a pattern for each previously
send command.
The simpler model is realy to send the first command, wait for a response,
send the second the command , wait for the response and so on.
Aside this model, you can also use expect_before to record pattern with
a given spawn_id.
It allows to bundle the send command and the expect_before
command within a single proc.
When do a loop with an empty expect statement.
At each loop iteration remove the expect_before pattern for the spawn_id
which has been matched.
If I have time, I'll post a code sample.
Your idea seems be veri interesting. But I afraid that I all understand.
Some code certainly will help me. Maybe if you are temponary very
bussy you may put here any link which describe widely about it. While
that i will try yours early suggests.
Thanks for all.
Sincerely Sebastian