Re: any trick I need to know to use "expect -i"?
- From: JJ <nomail@xxxxxxxxxx>
- Date: Thu, 05 May 2005 09:45:44 -0500
Khaled,
My telnet session actually is to connect my debug port. It is a kind of shell. It can receive commands, and print out some messages as well. It will never have EOF. [connectToMyDevice] was to connect a test set and read some data from it. With or without it, my Expect code sill couldn't send my dump command to my debug pot. I believe it is irrelavent to the problem.
I am a TCL and Expect newbie, and just borrowed the Expect book from my friend in attempt to "hack" expect. Maybe, I spent too less time on it. But according to the book, "expect -i" should work for me. And it seemed to me that my $expect_out(spawn_id) line was redundant.
Since I couldn't make my original Expect code work, I use another approach. Instead of using "-i", I wrote separate Expect scripts and used fifo files to communicate each other. It seemed work for me.
Still, I am very curious about how "expect -i" exactly works.
Thanks for your helps, joe
Khaled wrote:
JJ wrote:
Hi, I just learned TCL and Expect to debug my code. At the beginning, I wanted to use "expect -i" to handle several sessions at the same
time.
but at the end, I gave up.
What I wanted it to do was that it sent some debug commands to dump
some
info when my program printed out some certain string. But I failed:
my
expect code sometimes could detect the string and sent the debug commands, but sometimes it didn't.
Due to time constraint, I had to focus on my original bug, instead of
making my Expect code work. So I gave up then. (I did it manually for
very long hours)
Now, I have time and think Expect is kind of powerful for debug
(yeah,
if it can work,:)), so I come back to my expect code. But I still
can't
figure out what was wrong with my expect code.
any idea? Thanks, jj
======= set timeout -1 spawn telnet $host1 $port1 set s1 $spawn_id;
spawn telnet $host2 $port2 set s2 $spawn_id
spawn telnet $host3 $port3 set s3 $spawn_id
while 1 { expect -i "$s1 $s2 $s3" "BOM" { set spawn_id $expect_out(spawn_id) ;# I have to use this line. otherwise, the cmd wouldn't be sent to the correct session. why?? send "dumpInfo\n" set i [connectToMyDevice];#connect to a device. and get a number. . . . } } ======
Hello,
set spawn_id $expect_out(spawn_id) ;# I have to use this line. otherwise, the cmd wouldn't be sent to the correct session. why??
Because spawn_id here would contain that of the last spawned process, in your case $s3. Here, you want to send to the very process from which the pattern "BOM" was received. The spawn_id value of that process is stored in expect_out(spawn_id).
expect code sometimes could detect the string and sent the debug commands, but sometimes it didn't.
Generally, you need to do something like this for your expect to work:
set spawnList [list $s1 $s2 $s3]
while {1} { expect { -i $spawnList "BOM" { ... exp_continue } eof { catch {close -i $expect_out(spawn_id)} wait -nowait -i $expect_out(spawn_id) # then remove this spawn_id from spawnList set ind [lsearch -exact $spawnList $expect_out(spawn_id)] set spawnList [lreplace $spawnList $ind $ind] # break if there are no more open processes if {![llength $spawnList]} {break} exp_continue } } }
If this didn't solve your problem, pls quote the code of [connectToMyDevice].
Rgrds, Khaled
.
- Follow-Ups:
- Re: any trick I need to know to use "expect -i"?
- From: Khaled
- Re: any trick I need to know to use "expect -i"?
- References:
- Re: any trick I need to know to use "expect -i"?
- From: Khaled
- Re: any trick I need to know to use "expect -i"?
- Prev by Date: Re: Tk table
- Next by Date: Re: string inserts and database issues
- Previous by thread: Re: any trick I need to know to use "expect -i"?
- Next by thread: Re: any trick I need to know to use "expect -i"?
- Index(es):
Relevant Pages
|