Example:
spawn telnet to host1
... send a commands to set up the system ...
spawn telnet to host2
... send a few commands to cause host2 talk to host1 ...
Now, return to host1 to check for outputs
... might need to go back and forth for many test scenarios ...
/Why Tea
The Book has a chapter on this. Briefly, Expect has the intelligence
to manage handles to several spawned processes. I don't know what
kind of answer you're after apart from the pertinent chapter in the
book; it exactly addresses, "the proper way ..."
Is there a more specific question you have in mind? Are you after
example code?
set host1_id $spawn_id
> ... send a commands to set up the system ...
> spawn telnet to host2
set host2_id $spawn_id
> ... send a few commands to cause host2 talk to host1 ...
> Now, return to host1 to check for outputs
> ... might need to go back and forth for many test scenarios ...
expect -i $host1_id {something to see on host1}
send -i $host1_id "a command for host1\r"
expect -i $host2_id {something to see on host2}
send -i $host2_id "a command for host2\r"
even wait for both hosts simultaneously
expect {
-i $host1_id -re {something from host1} {
# do something...
}
-i $host2_id -re {something from host2} {
# do something...
}
}
--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry
note that the above method order the interaction, nothing
is going on with host2 until host1 is dealt with.
> even wait for both hosts simultaneously
>
> expect {
> -i $host1_id -re {something from host1} {
> # do something...
> }
> -i $host2_id -re {something from host2} {
> # do something...
> }
> }
>
>
>
this allows whoever is ready first to proceed.
And you can even look for the same thing from multiple
spawn_ids all together and in the processing you can
get which ID matched.
set spawn_list [list $host1_id $host2_id]
expect {
-i spawn_list
-re {pattern1} {
puts " matched pattern1 on spawnid: $expect_out(spawn_id)"
send -i $expect_out "next command"
}
{pattern2} {
# take some other action
}
}
Bruce
uwe