我正在尋找某種功能來在標準輸出中「偷看」,而不從預期的緩衝區中移除它,以便可以通過另一個期望命令讀取它。或者,有沒有辦法在閱讀後將它放回緩衝區?有沒有一種方法可以預期輸出而不將其從Tcl中的緩衝區中移出呢?
編輯:有人問了一些代碼,它基本上是一個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提示檢測,但這不是理想的,並且實際上已經導致一些錯誤。
你能發表一些代碼嗎? – pn8830