I have a question about the following code in TCL/EXPECT:
expect {
timeout {
puts "timeout error"
}
-re "Please enter the play name" {
exp_send $common1
exp_continue
}
-re "Please enter the play name_type" {
exp_send $common2
exp_continue
}
-re "Now you can get the information of the play" {
expect {
-re "\r"
}
}
}
if I run the code above, it will be stuck at the second code block(-re “Please enter the play name_type”). why this will happen? and if I move the second code block(-re “Please enter the play name_type”) on the top, the first two will pass. what is the reason?
And seems like the third code block is never executed, I added some trace inside of it like this: puts "executed!!!!" , the message never shows, and seems like it ignored the third code block and executed the code under the whole expect block, how to fix it?
Since the first pattern is a substring of the second pattern, the first pattern will match twice. When using
expect -reit is commonly suggested to match up to the end of a line, soI’m making as assumption that the question ends with colon, space and end of line. Adjust accordingly.
My usual expect advice: when you’re debugging or developing your program, add
exp_internal 1to the top of the script.