使用 expect 自动化调试脚本

Automation of a debugging script using expect

在运行一个调试命令之后,它的输出非常大..所以在某些时候它一直在询问

Type <return> to continue,or q <return> to quit

现在我想为不同的 bugs.But 自动执行这些命令我上面提到的这个特定语句在为不同的调试时不断变化 bugs.Sometimes 一个错误出现两次,另一个错误有时出现五次bug.How 我是否编写一个 expect 脚本来为这些提供继续选项?

如果我们不知道某些模式出现的顺序甚至次数,那么 exp_continue 是正确的命令。

expect {
    <pattern1> {send "cmd1"; exp_continue}
    <pattern2> {send "cmd2"; exp_continue}
    <pattern3> {send "cmd3"}
}

在上面的例子中,假设pattern1pattern2可能不是以相同的顺序到达并且出现的次数也不同,那么cmd1cmd2将被发送并且 Expect 仍将再次 运行。

命令exp_continue允许Expect本身继续执行而不是像往常一样返回。这对于避免显式循环或重复的 expect 语句很有用。

默认情况下,exp_continue 重置超时计时器。如果使用 -continue_timer 标志调用 exp_continue,则不会重新启动计时器。

对于你的情况,我们可以这样写,

expect {
    "Type <return> to continue,or q <return> to quit" {send "\r";exp_continue}
    "some-more-patterns" {#handler_here}
}