在 expect 输出中搜索单词
searching for a word in expect output
我有一个期望命令
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)?
的结果
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} {
我有一个期望命令
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)?
的结果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} {