Weird TCL Expect problem
Hi all,
I hope someone can help me out here. I have a TCL expect script that spawns a telnet session to a Nortel DMS100 to execute some commands. The strange thing is that the response in expect_out is not consistent. It sometimes contains a extra enter or newline. This results in differences in the expect out buffer. Here is a part of the script:
send "time\r"
sleep 1
expect -re ">"
set output $expect_out(buffer)
set output [split $output "\r\n"]
puts $output
This command displays the time. The correct output should be (with log_user=1):
>time
Time is 11:44:04
>
But sometimes the output is:
>timeTime is 11:45:04
>
As you can see here the \r is missing on the command that expect sends , or at least in the echo that is comming back.
I use a split command to filter out the response in the expect_out buffer, but this fails when the \r is missing. Here is a example with the debug enabled:
Wrong:
----------------------------------------------------------
send: sending "time\r" to { exp4 }
expect: does "" (spawn_id exp4) match regular expression ">"? no
timeTime is 11:47:11
>
expect: does "timeTime is 11:47:11\r\r\n>" (spawn_id exp4) match regular expression ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "timeTime is 11:47:11\r\r\n>"
{timeTime is 11:47:11} {} {} >
-----------------------------------------------------------
Good:
------------------------------------------------------------
send: sending "time\r" to { exp4 }
expect: does "" (spawn_id exp4) match regular expression ">"? no
time
Time is 11:47:59
>
expect: does "time\r\nTime is 11:47:59\r\r\n>" (spawn_id exp4) match regular expression ">"? yes
expect: set expect_out(0,string) ">"
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "time\r\nTime is 11:47:59\r\r\n>"
time {} {Time is 11:47:59} {} {} >
--------------------------------------------------------------
I suspect it has something to do with a slow response of the switch. I tried to send the time command slow and with the send_human but the result is the same. A timeout between the send and expect also doesen't help.
Does anyone here have a clue how to further debug/fix this issue?
Thanks,
Jenus
|