问题
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:
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" }
}
}
来源:https://stackoverflow.com/questions/6086617/expect-script-to-send-different-string-outputs