Version 4 of interact

Updated 2005-09-22 22:02:52

Interact is an Expect command which "[g]ives control of the current process to the user, so that keystrokes are sent to the current process, and the stdout and stderr of the current process are returned." [L1 ]

Interact is quite amazing. [Elaborate]

While there is Expect for languages other than Tcl, in the sense that a few other languages have extensions that (partially) manage ptys and demand-response dialogues, I know of no other that offers interact's functionality. On the other hand, interact is part of the evidence that most programmers don't know what Expect can do for them; only a tiny minority of Expect scripts appear to invoke interact.

To further elaborate, interact can be thought of as Expect's expect command's big brother. Libes created it (like the expect command) such that it is actually an event loop. When executed, interact returns control of the spawned process to a user (yes, or a program) but allows you to match on tty events (such as eof) or data so that the Expect script resumes control and performs whatever actions defined for the match. As interact will watch input and output at the same time, it is possible to set it to watch keyboard input for a signal, a predefined key sequence, and execute a Tcl procedure corresponding to it - like maybe save all input and output data to a file from then on.

The interact and expect command structures are similar as are their functionality. The major difference is that interact sets up a background matching event loop. expect blocks foreground processing (and ignores user input) during it's matching event loop. interact also has a set of switches that allow programmers to spawn two sessions and connect their ptys, thus letting them drive each other. An example of this is Don Libes' kibitz (and xkibitz) that come packaged with the Expect extension.