Reputation: 621
I am writing a tcl/expect script to check for the a string output of an event and if found then do something. Below is the code i have,
proc cli_detect_event {cmd value} {
cli_send "$cmd"
expect -timeout 3 $value {
} timeout fail
}
So when i send $cmd i get and event which should match $value hopefully. I was wanting to know is there a way to prevent what's in the expect_out(buffer) from being thrown away when expect is used again after this proc, so that I could expect match on the same outputs from the command I sent?
Upvotes: 1
Views: 1879
Reputation: 176
AFAIK no.
If the timeout occured then the buffer can be searched by next expect clause. But if the $value matched then everything up to this point including the $value itself is thrown away from the buffer (and printed to user).
Upvotes: 0
Reputation: 1550
The expect buffer variable is associated with its spawn_id variable, thus to ensure that your expect_out(buffer) is used you can just pass in the spawn id
proc cli_detect_event {cmd value spawnId } {
cli_send "$cmd"
expect -i $spawnId -timeout 3 $value {
} timeout fail
}
This should fix your issue. The only thing is that you need to ensure you save the spawn_id when you spawn a process
Upvotes: 0