Version 12 of exp_continue

Updated 2006-09-04 10:48:25

The standard documentation appears for this under-appreciated command in the Expect extension here [L1 ].

exp_continue isn't strictly necessary. One could write a loop from other, more primitive, elements. However, exp_continue is a great convenience for the common situation where it can be used to easily implement various client/server models in expect, such as FTP, SMTP or HTTP, where we are uncertain about the number and order of commands sent by server. [explain much more]

exp_continue is labeled as "under-appreciated" above because there's such a gap between the large number of people who can program basic exp_send-expect sequences, and the small minority who are familiar with exp_continue, despite the latter's usefulness.

[provide sample code for some client/server]

An example that uses exp_continue ( check if a user/password combination is valid ):

 proc auth_user { user pass } {
        global spawn_id
        set success 0 
        log_user 0
        spawn ssh -l $user localhost
        set spid $spawn_id

        expect -i $spid \
                  "word: "      {
                                exp_send -i $spid "${pass}\r"
                                if { $success == 0 } {
                                        incr success -1 
                                        exp_continue 
                                }
                } "> "  {
                        exp_send -i $spid "exit\r"
                        set success 1
                } "continue connecting (yes/no)? "      {
                        exp_send -i $spid "yes\r"
                        exp_continue 
                } "incorrect"   { 
                        set success -4
                        exp_send -i $spid "\r"
                } "try again."  { 
                        set success -4 
                        exp_send -i $spid "\r"
                } timeout       { 
                        set success -1 
                } 

        exp_close -i $spid
        exp_wait
        puts stderr authuser:$success
        return [ expr ( $success == 1 ) ? 1 : 0 ]
 }

[Category Command|Category Expect]