为expect中的每场比赛执行一个动作
我是一个完全期待的菜鸟。
我正在为一个测试用例编写一个期望脚本,我想计算字符串“Ok”出现的次数,并对以下输出中的每个出现执行一个操作:
Reloading configuration on all nodes
Reloading configuration on node 1 (node1-c5)
OK
Reloading configuration on node 2 (node2-c5)
OK
Reloading configuration on node 3 (node3-c5)
OK
Reloading configuration on node 4 (node4-c5)
OK
我的期望块是什么样子?
I am a total expect noob.
I am writing a expect script for a test case where I want to count the number of occurrences of the string "Ok" and do an action for every occurrence from the following output:
Reloading configuration on all nodes
Reloading configuration on node 1 (node1-c5)
OK
Reloading configuration on node 2 (node2-c5)
OK
Reloading configuration on node 3 (node3-c5)
OK
Reloading configuration on node 4 (node4-c5)
OK
How would my expect block look like?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会重写您的代码以删除
while
循环:请注意,Tcl 正则表达式要么完全贪婪,要么完全非贪婪。我使用
\r\n(.+)\r\n
捕获“正在节点上重新加载配置...”之后的行。但是.+
部分不能包含换行符,因此它必须是非贪婪的。因此,node_patt 中的每个量词都必须是非贪婪的。I'd rewrite your code to remove the
while
loop:Note that Tcl regular expressions are either entirely greedy or entirely non-greedy. I use
\r\n(.+)\r\n
to capture the line following "Reloading configuration on node ...". However the.+
part must not contain newlines, so it has to be non-greedy. Thus, every quantifier innode_patt
has to be non-greedy.代码最终看起来像这样(一个简单的循环):
The code ended up looking like this (a simple loop):