Re: any trick I need to know to use "expect -i"?



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

.



Relevant Pages

  • Re: ShellExcute for non EXE files
    ... the question is how to send commands to a ... command window. ... callback mechanism from that DLL that send received text to our app. ... >a TN3270 session that allows me to connect to Mainframe server. ...
    (microsoft.public.vc.mfc)
  • Problem with debug command in expect, command echoes back, issue in setting multiline value to a var
    ... I am facing a problem related to expect debug command. ... I'm using debug command in a script. ... I've an application (a test management execution engine ... I can use all tcl commands at the debug mode. ...
    (comp.lang.tcl)
  • Turning off echoing back of commands in debug command in expect
    ... I am facing a problem related to expect debug command. ... I'm using debug command in a script. ... I've an application (a test management execution engine ... I can use all tcl commands at the debug mode. ...
    (comp.lang.tcl)
  • Re: How to detect if is it system service ?
    ... the account the code is running under, for instance most services run under the system account. ... In Vista and later you could also check the session since services run in Session 0 while normal code runs in other sessions. ... It should pass errors on to the calling program and let that handle the errors. ... However there are some reasons which make this acceptable in this case: it is only done in debug builds and also it is only done when "sky is falling" type of error is detected and it is then easy to attach the debugger to the program and then debug the situation. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to detect if is it system service ?
    ... the account the code is running under, for instance most services run under the system account. ... In Vista and later you could also check the session since services run in Session 0 while normal code runs in other sessions. ... It should pass errors on to the calling program and let that handle the errors. ... However there are some reasons which make this acceptable in this case: it is only done in debug builds and also it is only done when "sky is falling" type of error is detected and it is then easy to attach the debugger to the program and then debug the situation. ...
    (microsoft.public.win32.programmer.kernel)