2012-04-18 58 views
1

在我的腳本中,我想返回不匹配的字符串。 我試圖puts $expect_out(buffer),但它沒有工作,給了我下面的錯誤如何在預期中返回不匹配的字符串

can't read "expect_out(buffer)": no such variable 
    while executing 
"puts "out is $expect_out(buffer)" " 

代碼

expect { 
    -nocase -re "$arg3" { exit 0 } 
    timeout { puts "Does not matched, output is $expect_out(buffer)" ; exit 2 }" 
} 
+0

你的代碼和你的錯誤信息不太匹配;也可以在_exactly_上覆制事物,以便微妙之處不會導致問題。 – 2012-04-19 09:32:42

回答

0

expect_out數組不存在,直到找到匹配,因此,如果您還沒有匹配的期望先前調用您的代碼,並且實際上您達到了超時條款,則會收到no such variable錯誤。

期待手冊頁

「經匹配的圖案(或EOF或full_buffer),任何匹配的和先前無法比擬的輸出被保存在變量expect_out(緩衝液),9個正則表達式的子串匹配被保存在變量expect_out(1,string)through expect_out(9,string)。如果在模式之前使用-indices標誌,則將10個字符串的開始和結束索引(以適合於lrange的形式)存儲在變量中expect_out(X,start)和expect_out(X,end)其中X是一個數字,對應於緩衝區中的子串位置0指的是匹配整個模式併爲glob模式生成的字符串,以及re gexp模式「。

您可以通過info exists expect_out測試此並且使用array names expect_out打印出數組鍵/值(如果存在)。

您可以通過set expect_out(key) value自己設置值的明確度,但是我沒有辦法(我知道)最初檢索到不匹配的字符串,使用log_file expectoutput.txt來檢索,如果超時,則將其重新讀回。

相關問題