문제

I need to spawn a script that produces lots of output which makes the regex matching of the output slow. Also the buffer fills quickly even when I use quite a large match_max value.

I would like to check the output for a particular string. If the string does not exist, I would like to discard the output read so far.

I have tried using default matches, globs and negative regexes to catch the unwanted strings, but could not get this working.

How can this be done with expect?

도움이 되었습니까?

해결책

This 'seems' to work (more testing is required):

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; }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top