2014-02-17 44 views
0

我需要產生一個腳本,產生大量的輸出,使輸出緩慢的正則表達式匹配。即使我使用相當大的match_max值,緩衝區也會快速填充。期望 - 如果預期的字符串未找到如何丟棄緩衝區

我想檢查特定字符串的輸出。如果字符串不存在,我想放棄迄今爲止讀取的輸出。

我已經嘗試使用默認匹配,globs和負面正則表達式來捕獲不需要的字符串,但無法得到這個工作。

這是怎麼做到的期望?

回答

0

這 '似乎' 工作(需要更多的測試):

set success_string "\[INFO\] Started Jetty\r\n" 

spawn "/usr/bin/mvn" "-pl" ":cloud-client-ui" "jetty:run" 
expect { 
    -re "(\[^\r]*\)\r\n" 
    { 
    set current_line $expect_out(buffer) 
    if { [string equal "$current_line" "$success_string"] } { 
     puts "exiting with matched string $current_line" 
     exit 0 
    } else { 
     puts "discarding $current_line" 
     exp_continue 
    } 
    } 
    eof { puts "eof"; exit 1; } 
    timeout { puts "timeout"; exit 1; } 
} 
相關問題