我的期待会话与此类似:
spawn myapp
stratos> list-tenants
Available Tenants:
+-----------+-----------+-------------+--------+---------------------------+
| Domain | Tenant ID | Email | State | Created Date |
+-----------+-----------+-------------+--------+---------------------------+
| frank.com | 1 | foo@bar.com | Active | 2014-02-26T11:33:23+05:30 |
+-----------+-----------+-------------+--------+---------------------------+
stratos>
流程大致是:
如何匹配期望的第3步输出?即我需要更换 ???? ,在下面?
请注意,expect脚本是测试的一部分,其中输出由应用程序调用的模拟服务生成,因此我希望逐字匹配整个输出。
expect "stratos>"
send "list-tenants\r"
expect {
???? { exp_continue; }
timeout { puts stderr "Expect could not match 'Available Tenants:'"; exit 1; }
}
非常感谢。
答案 0 :(得分:1)
试试这个:(未经测试)
spawn myapp
set prompt_re {stratos> $}
expect -re $prompt_re
send -- "list-tenants\r"
expect {
timeout {error "could not match available tenants"}
-re "list-tenants(.+)$prompt_re"
}
set available_tenants [string trim $expect_out(1,string)]