我想"监听"shell输出的字符串,同时处于"交互"模式.或者我想以某种方式模拟交互模式,这仍然允许我从shell中侦听特定的字符串.
它似乎interact只监听用户输入(我按下的键)而不是shell返回的内容.
每次看到特定字符串时,我如何让Expect执行某些操作,但是否则让我以交互方式使用shell无阻碍?
例:
proc yay {} {
send_user "Yay\n"
}
trap { # trap sigwinch and pass it to the child we spawned
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH
spawn bash
interact {
interact -re "HOT" {
yay
}
expect {
fuzz yay
}
}
Run Code Online (Sandbox Code Playgroud)
如果我运行它并键入"HOT",它将以"Yay"响应.正如所料,它读了我的钥匙.但如果我输入
echo fuzz
Run Code Online (Sandbox Code Playgroud)
"expect"子句不会被触发."echo HOT"也不会触发任何东西.
这是可能的,还是我错过了什么.也许我需要模仿interact某种"期待,继续" - 循环.重要的是一切都在shell中正常工作..
有人建议吗?
expect ×1