【发布时间】:2013-02-04 15:48:05
【问题描述】:
我发现 send 命令之后的 expect 命令匹配来自 send 命令的数据。
让我们看看,my.sh:
#!/bin/sh
read line
echo ok
my.exp(有些代码是多余的,我模拟 DejaGNU 测试框架...):
set passn 0
proc pass {msg} { global passn; incr passn; send_user "PASS: $msg\n" }
set failn 0
proc fail {msg} { global failn; incr failn; send_user "FAIL: $msg\n" }
proc check {} {
global passn failn;
send_user "TOTOAL: [expr $passn + $failn], PASSED: $passn, FAIL: $failn\n"
if {$failn == 0} { exit 0 } { exit 1 }
}
set timeout 1
spawn ./my.sh
send hello\n
expect {
-ex hello {
send_user "~$expect_out(0,string)~\n"
pass hello
}
default { fail hello }
}
expect {
-ex ok { pass ok }
default { fail ok }
}
check
当运行 expect my.exp 我得到:
生成 ./my.sh 你好 ~你好~ 通过:你好 好的 通过:好的 总计:2,通过:2,失败:0我不明白为什么 hello 匹配!请告诉我。我已经重读了:
【问题讨论】: