Another Expect jewel, somewhere between spawn and interact. http://www.cotse.com/dlf/man/expect/overlay.htm outlines its functionality.
Also see http://expect.nist.gov/FAQ.html#q16