我正在寻找某种功能来“窥视”标准输出,而不会将其从期望的缓冲区中删除,以便可以通过另一个期望命令读取它。或者,有没有办法在读取后将其放回缓冲区?
编辑:被要求提供一些代码,它基本上是一个类似于以下内容的 shell 提示:
(prompt) bad_command_that_was_sent
error message
(prompt) successful_command_that_was_sent
(prompt) other_successful_command
long barf of data that has
very little consistency
and almost no way to tell when it\'s
about to end as the prompt just shows
up again suddenly but I really want to save
it and parse it.
(prompt)
现在我是这样看的:
expect {
-re "Error message regex" {error handling part}
-re "Prompt regex" {anything I need to do with successes}
}
我目前正在使用一种解决方法,我发送一个额外的换行符 ( send "command\r\r"
),它可以让我得到 2 个提示来检测,但这并不理想,并且实际上是/已经导致了一些错误。