If you're using the expect
command to wait for one of a series of inputs within your expect program, information will be checked in the program's internal buffers inthe following order:
a) Any string that matches expect_before
will be found
b) Matches to each of the possible patterns in expect
c) Matches to expect_after
Note that you can't be certain how much information will have been written to the internal buffer up to any point, so you need to exercise care when specifying the possible sequences.
Once expect_before expect_after or expect matches as string, the section up to that string is transferred to the expect_out(buffer) variable that you can reference in your continuing Tcl, and that section is removed from the internal bugger. The following expect
command will start looking from where the previous successful match was found.
Note that the -notransfer
option to expect will prevent the matched section from being removed from the internal buffer.
command allows you to specifiy an expect command that runs, in effect, in an asyncronous background loop. You can use it to receive inputs from processes that may be responding from time to time while you're doing other processing in the foreground, without having to go into a wait loop until one of those background processes responds. (written 2007-10-27, updated 2007-10-30)
Associated topics are indexed underT211 - Tcl/Tk - What is Expect? Why use it? 
Adding Expect on top of Tcl - what is it and where can I get a training course to learn about it? - (2012-01-08) 
Should we cover expect and/or Tk on our public Tcl courses? - (2011-05-11) 
Expect in Perl - a short explanation and a practical example - (2010-10-22) 
Parallel Pinging, using Python Threads or Expect spawn lists - (2009-11-02) 
Using Tcl and Expect to automate repetitive jobs - (2009-10-24) 
Automating processes through Expect - (2008-04-05) 
Expecting a item from a list of possibles - (2008-02-04) 
Curley brackets v double quotes - Tcl, Tk, Expect - (2007-12-12) 
What is Expect? - (2007-10-26) 
Installing Tcl and Expect on Solaris 10 - a checklist - (2007-05-02) 
Cheat Sheet / Check list for Expect maintainers - (2007-05-02) 
Expect for Windows - (2005-09-04) 
Automating regular manual procedures - (2005-04-21)T242 - Tcl/Tk - More on Expect 
Checking all the systems on a subnet, using Expect and Tk - (2011-09-18) 
Quick easy and dangerous - automated logins via Tcl / Expect - (2009-10-24) 
Tcl/Tk - updating your display while tasks are running - (2007-12-16)
Some other Articles
Better technology makes for longer commutes?What we teach - expained for the non-technicalThe little gestures that can really countSparse and Greedy matching - Tcl 8.4Buffering of inputs to expect, and match orderTcl / regsub - changing a string and using interesting bitsWireless hotel tips - FTP and Skype connections failingReading from another process in Tcl (pipes and sockets)Away or home - which do I prefer?