Updated 2009-07-16 14:22:04 by MJ

[Make time to explain recurring question about expecting alternatives.]

Model question: "need something like 'if expect is {y/n} send y; if not, send quit'". Skeleton answer:
    expect {
        y/n {
            send y\r ; exp_continue
        timeout {
            send quit\r

LV: The above code confuses me a bit - it looks as if it sends along to the program a "y" if the user types "y/n" - was that intentional?

escargo 11 Aug 2008 - That would seem to be a restatement of the model question. As long as the timeout is reasonable, it should work. Better would be to anticipate some other alternatives so that waiting for the timeout is less necessary.

Lars H: Isn't the situation rather that Expect is acting "user" to some other program? That program might do what it is supposed to without questions, but it might also stop to ask something (question ending with y/n), and in that case Expects acts drinking bird pressing the 'y' key [1].

LV: Ah - I see. So the code above says "watch the output of some program. When it outputs the string "y/n", respond by sending a "y" and "pressing return".

Sorry, it has been a long time since I coded any expect, and got the whole thing backwards.

MJ - If you expect several y/n questions, you'll need to use [exp_continue].