【问题标题】:searching for a word in expect output在期望输出中搜索单词
【发布时间】:2017-02-24 15:47:28
【问题描述】:

我有一个期望命令

expect "~]#" { send "virsh list --all\r"}

输出将是

[root@lht1oneems-unit0 ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 399   lht1duplexvm-0                 running
 -     rhelvm                         shut off

我想使用 $expect_out(buffer) 并有一个 if 语句在它发现运行时执行某些操作,否则执行其他操作。 如何解析 $expect_out(buffer) 的结果?

【问题讨论】:

    标签: linux parsing output expect


    【解决方案1】:
    expect "~]#"
    send "virsh list --all\r"
    
    # I assume another prompt follows this
    expect "~]#"
    
    if { [regexp {running} $expect_out(buffer)] } {
        do-something-for-running-process
    } else {
        do-something-for-no-running-process
    }
    

    你也可以

    if {[string first "running" $expect_out(buffer)] >= 0} {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多