0

I have something like this.

expect 
 "hi"    { send "You said hi\n" } 
 "hello" { send "Hello yourself\n" } 
 "hi"    { send "2nd time you said hi\n" }

The scenario is I will get a initial response 'hi', then 'hello', then 'hi' again. The second time I get a response of 'hi', I want to send a different string.

Thanks.

1

1 Answer 1

3

You should use a list and iterate...

set responses {{You said hi} {2nd time you said hi}}
set idx 0
while {$idx < [llength $responses]} {
    expect {
     "hi"    { send [lindex $responses $idx]\n; incr idx } 
     "hello" { send "Hello yourself\n" } 
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.