问题
The doc says:
takes the same arguments as
expect
, however it returns immediately.
But what does it mean by "returns immediately" ?
What's the usage of this command could be ?
回答1:
Image you have spawned a program that, say, randomly asks "Are you sure [yn]?"
Imagine this program has 100 questions that need to be answered.
You don't want to have to conditionally expect an "Are you sure" question for each of those 100 questions.
Expect lets you do:
spawn /some/annoying/program
expect_before {
"Are you sure \[yn]?" {
send "y\r"
exp_continue
}
}
expect "first question"
send "first answer\r"
# and so on.
Now you are covered: expect implicitly adds the expect_before
code into each expect
command.
来源:https://stackoverflow.com/questions/61021868/whats-the-usage-of-expect-before-command-in-expect