Domanda

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?

È stato utile?

Soluzione

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; }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top