写expect脚本的几个坑

这段代码展示了一个使用expect脚本来自动化执行gen_info.py脚本的过程,针对每个$card,它发送命令并设置超时。如果超时,则记录错误信息并终止进程。当匹配到特定模式时,脚本会记录成功信息,并保存输出到变量。这个过程涉及到自动化测试和脚本编程。
摘要由CSDN通过智能技术生成

In general, expect will save the expect's whole match string in expect_out(0,string) and buffer all the matched/unmatched input to expect_out(buffer). Each sub match will be saved in subsequent numbering of string such as expect_out(1,string), expect_out(2,string) and so on.

 

foreach card $cardlist {
    send "./gen_info.py [string tolower $card] /usr/dump_log/Dump_Log/Apollo_log/PCB2C/$card\n"
    set timeout 200
    expect_before timeout {
        log_puts "gen_info.py for $card timeout"
        log_puts $expect_out(buffer)
        abort
    }
    # regexp matching is using greedy mode
    expect -re {/home/insieme.*json} {
        log_puts "gen_info.py for $card succeeded"
        log_puts $expect_out(0,string) # no space between 0 and string                                                                
        set  json_card($card) $expect_out(0,string)
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值