在我期望的剧本期间,它是超时的吗?

时间:2016-01-06 22:20:43

标签: timeout expect

在我的期望脚本expect_after中捕获来自BadPromptPassword的超时,但是如何返回这是我期望脚本超时的地方?我玩过expect_out并没有给我我需要的东西...任何帮助表示感谢。感谢

spawn telnet 172.27.228.239
expect {
    timeout { puts "Timed out waiting for response from telnet ('172.27.228.230',)."; exit 1}
    "Password:" { send "lab\r"; }
    "\[>#\]"
};

send "en\r"
expect_after {
    timeout {
      puts "a default timeout clause for all subsequent expect commands ";
      exit 1
    }
}
expect "#>"
send "admin"
expect "BadPromptPassword:"
send "lab\r"
close
wait

1 个答案:

答案 0 :(得分:0)

这是一个快速黑客

expect_after {
    timeout {
        puts "timed-out expecting $pattern";
        exit 1
    }
}

set pattern "#>"
expect $pattern
send "admin"

set pattern "BadPromptPassword:"
expect $pattern
send "lab\r"