Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

small problem

8 views
Skip to first unread message

ms

unread,
Sep 11, 2005, 2:00:09 PM9/11/05
to
Hi
I'm new in tcl. For truth i'm lerning expect.
I have to create program which will could connect with two different
computers. I can develop soft which will be connect only with one
server/computer but I don't know how make it with two.

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

Earl Grieda

unread,
Sep 11, 2005, 6:28:30 PM9/11/05
to

"ms" <seba...@SPAMpoczta.onet.pl> wrote in message
news:dg1rb3$lb1$1...@news.onet.pl...

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.


ms

unread,
Sep 11, 2005, 7:28:12 PM9/11/05
to
Earl Grieda napisał(a):
Yes I have read about it in manual. But the problem is that i don't know
how it use :( Any example would be invaluable!! For truth!!

Sincerely Sebastian

dba...@norspam.com

unread,
Sep 12, 2005, 3:58:32 AM9/12/05
to

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

ms

unread,
Sep 12, 2005, 5:51:58 PM9/12/05
to
dba...@norspam.com napisał(a):
That's great exactly this I have searched. All of it it's clear but I
have got one more question:
e.g. when I send to command by two spawned application and I have been
waiting for string expect'em. I set up that first respond spawn1 and I put:
expect -i spawn_id1 "string"
and after that:
expect -i spawn_id2 "another string"
and the response will be recive in opposite order. What would make
happen? Is program for thrue identify which string is designed to which
spawn application? Or would make something unforeseeable?

Sincerely
Sebastian

David Bariod

unread,
Sep 13, 2005, 4:27:39 AM9/13/05
to

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
#

Avnish

unread,
Sep 15, 2005, 10:26:53 AM9/15/05
to
Hi David,
Just wanted to confirm if there's any dependency on Expect version for
above block to work? If am correct this block will work with 5.42
onward as Non blocking IO channels were introduced in this version
itself.

Thanks
Avnish

David Bariod

unread,
Sep 16, 2005, 3:41:17 AM9/16/05
to

On Thu, 15 Sep 2005, Avnish wrote:

> 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 ?

ms

unread,
Sep 16, 2005, 12:25:18 PM9/16/05
to
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?

Thanks for your example, one more time :)

Sincerely Sebastan

David Bariod

unread,
Sep 19, 2005, 8:52:58 AM9/19/05
to
On Fri, 16 Sep 2005, ms wrote:

> 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.

ms

unread,
Sep 19, 2005, 4:05:00 PM9/19/05
to
> 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.
>
> ------------------------------
> David Bariod
> For email replace spam by tel
>

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

0 new messages