While loop in expect script

I'm new to scripting, I want to write something like this:

set variable;
$variable = expect -exact "\/----Enter Password----\\"
while { != $variable } {
send -- {^[-}
}

I want to keep sending escape + hyphens until I expect this prompt: "/ ---- Enter Password ---- \". I wrote the code above, but it does not work. How can I do this, kindly help me.

0
source share
1 answer

exp_continue . exp_continue , , , . . exp_continue timeout. , exp_continue -continue_timer.

expect 10 . , expect .

expect

expect "name"

"" , -. - timeout expect.

expect {
       "name" { # Some code here }
        timeout { # timeout_hanlder_code_here }
}

timeout, set, .

set timeout 60; # Timeout will happen after 60 seconds.

, ,

expect { 
        # If the phrase 'Enter Password' seen, then it will send the password
        "Enter Password" {send "yourpassword\r"}
        # If 'timeout' happened, then it will send some keys &
        # 'expect' will be looped again. 
        timeout {send -- {^[-}; exp_continue}
}

. . , escape + . ([) (-). , , "". . .

Escape .

send -- \033-; # Sending Escape + hyphen together

\033? Escape. -, \033-. , ,

expect { 
            # If the phrase 'Enter Password' seen, then it will send the password
            "Enter Password" {send "yourpassword\r"}
            # If 'timeout' happened, then it will send some keys &
            # 'expect' will be looped again. 
            timeout {send -- \033-; exp_continue}
    }

: Tcl wiki ASCII Char

+3

All Articles