Michael Walsh | aa245bb | 2018-02-20 11:30:00 -0600 | [diff] [blame] | 1 | #!/usr/bin/expect |
| 2 | |
| 3 | # This file provides many valuable expect procedures like handle_timeout and |
| 4 | # handle_eof. |
| 5 | |
| 6 | my_source [list print.tcl] |
| 7 | |
| 8 | |
| 9 | proc handle_timeout { description } { |
| 10 | |
| 11 | # Print timeout error message to stderr and exit 1. |
| 12 | |
| 13 | # Description of argument(s): |
| 14 | # description A description of what was being expected |
| 15 | # (e.g. "an SOL login prompt"). |
| 16 | |
| 17 | set timeout [get_stack_var timeout {} 2] |
| 18 | |
| 19 | if { $timeout == 1 } { |
| 20 | set seconds "second" |
| 21 | } else { |
| 22 | set seconds "seconds" |
| 23 | } |
| 24 | puts stderr "" |
| 25 | print_error "Did not get ${description} after $timeout ${seconds}.\n" |
| 26 | puts stderr "The data returned by the spawned process is:\n" |
| 27 | # Using uplevel to be able to access expect_out(buffer). |
| 28 | uplevel { puts stderr "$expect_out(buffer)" } |
| 29 | # If caller has exit_proc defined, call it. Otherwise, just call exit. |
| 30 | if { [info procs "exit_proc"] != "" } { |
| 31 | exit_proc 1 |
| 32 | } |
| 33 | exit 1 |
| 34 | |
| 35 | } |
| 36 | |
| 37 | |
| 38 | proc handle_eof { description } { |
| 39 | |
| 40 | # Print end-of-file error message to stderr and exit 1. |
| 41 | |
| 42 | # Description of argument(s): |
| 43 | # description A description of what was being expected |
| 44 | # (e.g. "an SOL login prompt"). |
| 45 | |
| 46 | # Using uplevel to be able to access expect_out(buffer). |
| 47 | puts stderr "" |
| 48 | print_error "Reached end of file before getting $description.\n" |
| 49 | puts stderr "The data returned by the spawned process is:\n" |
| 50 | # Using uplevel to be able to access expect_out(buffer). |
| 51 | uplevel { puts stderr "$expect_out(buffer)" } |
| 52 | # If caller has exit_proc defined, call it. Otherwise, just call exit. |
| 53 | if { [info procs "exit_proc"] != "" } { |
| 54 | exit_proc 1 |
| 55 | } |
| 56 | exit 1 |
| 57 | |
| 58 | } |