Re: tcl/expect hang



On May 6, 9:20 pm, kbuzz3...@xxxxxxxxx wrote:
On May 4, 7:04 pm, Bezoar <cwjo...@xxxxxxxxx> wrote:



On May 4, 1:05 pm, kbuzz3...@xxxxxxxxx wrote:

Hello,
I seem to be having a problem where my expect scripts seem to hang
sometimes. If I press 'enter' it will then continue to run the
script. I am not entirely positive but I believe it is related to the
sleep command. It does not happen consistently but when it does
happen it seems to happen in bunches. If it does happen due to sleep
it tends be ones that last a minute or more.
I have seen it happen in a couple of different scripts but the code
mostly looks something like:

while {$a < $b} {

send_user "*************\n"
send "router command \n"
expect {
"certain response" {
# parse expect_out buffer for results
}
timeout {
# quit script
}

}
send_user "parsed info\n"

inrc b
sleep 120

}

thank you in advance,
Matt

oops just saw your error you end all your send sequences with \n they
should be \r

so
send "router command\n" should be
send "router command \r"

Carl

Carl,
Just re-reading your post and you wrote "...saw your error...." Are
you saying that you think my problem is directly related to "\n" vs.
"\r"? Or are you just saying that you think that "\r" is a better
choice?

thanks,
Matt

I just say this because usually \r works all the time. If you've used
\n and it works then
thats good enough. I also have an idea of another way to implement
the sleep and that is
to use expect itself to do the sleep. See code below. You can also
put in an eof handler to
detect if the spawned process dies. See if this helps and let us know
if you have solved your
problem.

Carl

#!/opt/usr/bin/tclsh8.5
package require Expect

spawn /bin/sh
set timeout 3
expect {
"\#" {
puts "got prompt"
}
timeout {
puts "timeout"
}
}
# sleep 120 seconds
set timeout 120
set start [clock seconds ]
expect {
timeout {
set end [clock seconds ]
puts "slept for [ expr $end - $start ] sec "
}
}



.



Relevant Pages

  • Re: tcl/expect hang
    ... If it does happen due to sleep ... I have seen it happen in a couple of different scripts but the code ... set timeout 3 ... set timeout 120 ...
    (comp.lang.tcl)
  • Re: need help in capturing output from send command in EXPECT into text file
    ... set timeout 1 ... puts "gpt here" ... If you think you need sleep you need sleep ...
    (comp.lang.tcl)
  • Re: timeout a command in ksh
    ... sleep $itrunsforseconds ... Debian GNU/Linux 3.1 a.k.a. "sarge" with pdksh as ksh per alternatives ... "watchdog" timed out per our shorter timeout per the ... timeout in $maxseconds ...
    (comp.unix.shell)
  • Re: tcl/expect freeze
    ... I set the timeout to 70. ... scripts to run in a loop until it froze. ... So it would appear in this case that the spawn telnet line is ... spawn telnet $_router_ip $_port ...
    (comp.lang.tcl)
  • Re: Batch file and MFC (Properly Terminating Application)
    ... I have a function called DoEvents ... Sleep fucntion is within that loop as well as DoEvents ... while(!GetQueuedCompletionStatus(port, &bytes, &key, timeout)) ... if timeout also check for abort ...
    (microsoft.public.vc.mfc)