tcl expect - problem with regular expression in interact mode
Hi,
I have something like the following in my expect script: Code:
interact { e.g. 1.when I type "s" followed by "enter" key it should match. 2.if I type something like "chess" followed by "enter" key it shouldn't match. Unfortunately, the second case is also being matched by the regular expression I have in my code. Please help! |
I do not see the problem ...
Hi,
I created these two little scripts to verify your observation. However, it seems to work as expected: exp.scr Code:
#!/usr/bin/expect -f Code:
#!/bin/bash Here is the output I get: Code:
$ ./exp.scr Code:
$ ./exp.scr I assume that the missing second closing '}' is just a typo in your post. Otherwise, you might want to correct it. If have misunderstood your requirement then maybe you should post some real input/output of your program and what you actually expected. |
code output
Hi crts,
Thank you very much for your time. For me the problem occurred when I entered "chesss" and not "chess". I apologize for my mistake. And the missing "}" is a typo. I executed my code again but now with debugging info. My code: Code:
#!/usr/bin/expect -d Code:
host1:~# ./test |
Firstly, it is important to understand that the characters '^' and '$' anchor the beginning and end of received data. They do NOT anchor the beginning and end of a line.
To understand the observed behavior let's assume there is a "RegExBuffer" for the incoming data. Since you have defined two characters in your RegEx this buffer will hold up to two bytes. This buffer will be emptied as soon as it does not match the RegEx. Let's have a closer look at what happens when you type chess: Our RegEx is "s\r". 'c' is typed Code:
RegExBuffer [c][] --> RegEx is mismatched and the buffer is emptied Now the first 's' is typed Code:
RegExBuffer [s][] --> RegEx is starting to match; the buffer is not emptied Code:
RegExBuffer [s][s] --> RegEx is mismatched and the buffer is emptied Code:
RegExBuffer [\r][] --> RegEx is mismatched and the buffer is emptied Code:
RegExBuffer [s][] --> RegEx is starting to match again; the buffer is not emptied Code:
RegExBuffer [s][\r] --> This is a perfect match! The 'Exiting' branch is executed! To further verify the mechanism I described above you can change your RegEx to "ss\r". Now the RegEx buffer will hold up to 3 characters. Hence, the 'Exiting' branch will be executed whenever you enter 2,5,8 ... consecutive 's'. I am quite confident that there is a workaround for this problem; although not sure how it will look. It would be nice if you could post the solution here once you have it. |
All times are GMT -5. The time now is 01:58 PM. |