Chapter 15. Interact
In earlier chapters, interact was used in a very simple way. In reality, the interact command simplifies many tasks and opens up a world of new problems that can be solved. In this chapter, I will describe the more common uses for interact. In the next chapter, I will focus on using interact with multiple processes.
The interact Command
In Chapter 3 (p. 82), I introduced the interact command in the context of a script to automate ftp. The script carried out the initial part of the procedure—entering the user name and password—and then returned control to the user by calling interact.
The interact command is much more flexible than that example demonstrated. interact can also:
execute actions when patterns are seen from either a user or a spawned process
allow the user to take control of a spawned process, and return control to the script for further automated interaction, any number of times
suppress parts or all of an interaction
connect two or more spawned processes together, pairwise or in other combinations
Many of the things interact does can also be done by expect, but interact can do them more easily and efficiently. In this sense, interact is a higher-level command than expect. In other ways, expect and interact are duals. They do the same thing but have a very different way of looking at the world. As I explain interact, I will frequently bring up expect to compare the similarities and contrast the differences between the two.
In its simplest form, the interact ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access