Posted to tcl by rahl at Wed Nov 16 12:33:28 GMT 2022view pretty

set run_till_end 0

expect {
    "Some match" { do_stuff; exp_continue }

    "Other match" { do_other_stuff; exp_continue }

    "Final match" {
        # Not exactly stopping, but simplifying
        puts "== Stop expecting"
        set timeout 1
        set run_till_end 1
        exp_continue
    }

    timeout { 
        if {$run_till_end == 1} {
            expect {
                eof
                exp_continue
            }
        } else {
            exit 36
        }
    }

    eof
}