I'm automating some work with expect, and have something like the following:
# procedure to set background and after patterns
proc foo {} {
expect_after {
-re $regex1 {puts "Matched regex1"; send $command_to_run; exp_continue}
timeout {exp_continue}
}
expect_background {
-re $regex2 {do other things; exp_continue}
-re $regex3 {and more different things; exp_continue}
timeout {exp_continue}
}
}
spawn $thing
foo
expect_user {
-ex "stahp" {exit}
}
This hangs indefinitely after expect_after
pattern is matched (and the associated body is run). However, if I move the expect_after
and expect_background
patterns out of the procedure, then it runs as I, well, expected.
Why does it behave differently when put in a procedure?