expect and multiple processes
Posted by mathias77 (mathias77), 18 November 2003Hi,
I'm a rookie trying to learn expect
I have a question:
If I want my expect script to handle two processes at a time but in two different terminals how do I do that? I have tried by having the first process executing in the same terminal as I started the script and the second to work in a new terminal by spawning a new terminal and then saving the spawn_id. But when I want to send to this process I had no luck
Can anyone give a quick example that works involving a new terminal and sendin messages to both processes?
Posted by admin (Graham Ellis), 18 November 2003I suspect that your problem could relate to the fact that spawn sets the spawn_id, and when you do your second spawn you overwrite it. Expect and send relate to the current spawn_id by default, and its up to you to save and restore the spawn_id into another variable if you want to handle multiple processes. You might say "how old-fashioned". Yes - if Expect was being written today, no doubt an OO interface would be used ....
Here's a sample piece of code from our Tcl Basics course (see http://www.wellho.net/course/tbfull.html ) that controls two processes.
You may also like to note that the expect command can be instructed to wait for input from any one of a whole list of processes, using a list of process ids on which to wait and the -i option. Do post further if you would like an example of this - we use it to parallel ping all our training computers to test the network, and it's great because we don't have to wait for timeouts on each individual machine that may not be responding.
Posted by mathias77 (mathias77), 18 November 2003Ok,
thanks for your help!
Still I've got the problem with spawning a terminal and then trying to execute commands on the new terminal.
See the following example:
spawn dtterm -geometry 80x40+63+13 -title test -fg green -bg black
the 'ls' command is not executed in the new terminal.
Any idea on how to solve this?
Posted by admin (Graham Ellis), 19 November 2003I'm more familiar with xterm, and I would tend to use the -e option to start the terminal off with a specific command. `There's also a whole section on automatic xterm in Don Libes' book on expect - see
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho