Exercises, examples and other material relating to training module T211. This topic is presented on public courses Learning to program in Tcl
, Tcl Programming
, Tcl Programming
Expect is a Tcl extension that's heavily used by perhaps a third of our trainees. If you have an application that's designed for a human user, but you want to run it automatically, expect lets you mimic the human actions via a series of send and expect commands.
Related technical and longer articlesA Web interface for your Linux admin tasks
|Articles and tips on this subject||updated|
|4405||Backup procedures - via backup server|
Our main web server system becomes ever more important to our business - and having procedures in place to restore systems in the event of failure becomes ever more critical.
What are we protecting against? Both hardware and software failures, and against intrusions and obsolescence (to the extent of ...
|3572||Adding Expect on top of Tcl - what is it and where can I get a training course to learn about it?|
Expect adds extra commands on top of Tcl - allowing the Tcl programmer to control additional processes as is they were really being run from the command line. But because they're being run from within a program, a whole lot of commands can be run with little effort, responses analysed easily, with the ...
|3286||Should we cover expect and/or Tk on our public Tcl courses?|
A sizeable minority of our Tcl course delegates use the expect and / or tk extensions. And on our Tcl courses we handle the two differently. For Expect, we include some coverage in our standard agenda, running if required an hour or two into the evening of starting early in the morning to ensure substantial ...
|2489||Parallel Pinging, using Python Threads or Expect spawn lists|
Ping is a very useful command to use within scripts for checking the presence (or absence) of a live system on our network, or indeed on the Internet. However, there are subtle differences in the format of its report on different operating system flavors, so any code that you write that needs to analyse ...
|3009||Expect in Perl - a short explanation and a practical example |
Around 20% of delegates on our Tcl Courses are using Tcl because of the Expect package that extends it to "choreograph" interaction with other systems and processes, and yet the Expect module in Perl (Expect.pm) is decidedly niche and we cover it on our Perl for Larger Projects course only on request. ...
|2474||Using Tcl and Expect to automate repetitive jobs|
If you're typing the same series of instructions into your computer time and time again, perhaps with predictable variations depending on the responses that you get, you should consider using Expect. Expect adds three extra major commands to the Tcl language:
• spawn to start a process
• send ...
|1602||Automating processes through Expect|
What is Expect? Let me give you an example of how it's used to help answer that question.
I want to connect to a remote host that I can access through FTP, and have a look at all the files with "top", "sql" and "txt" in their names in my home directory. And that's something I need to do on a regular ...
|1531||Expecting a item from a list of possibles|
There are times (and they're quite frequent!) that I'm asked a good question that's so good it's worth sharing the answer. Actually, that makes up a fair proportion of my inspirations for this spot, such as today's.
In Expect - the command line automation tool of the Tcl language - you can tell the ...
|1469||Curley brackets v double quotes - Tcl, Tk, Expect|
In Tcl, both Curley braces and double quotes can be used to hold a block of program or data together as a single unit / parameter ... but there are differences ...
a) Curley braces can stretch over a number of lines, with new lines within the block being simply a part of the block. So they're ideal ...
|1411||Buffering of inputs to expect, and match order|
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 in turn
|1409||What is Expect?|
Expect is an extension to the Tcl language which provides three key new commands - spawn which lets you start up another process, send which lets you send information to that process and expect through which you can receive back responses from that process.
For the majority of users of Tcl, Expect is ...
|1174||Installing Tcl and Expect on Solaris 10 - a checklist|
Hot off the presses from the last couple of days - a check list (and a couple of "Gotcha" notes) concerning the installation of Tcl and Expect on a Solaris 10 system, compiling from scratch were possible.
You'll need a C Compiler
We used gcc (the Gnu C compiler) and we installed it from Sun standard ...
|1173||Cheat Sheet / Check list for Expect maintainers|
Programming in Expect can be very different (and more challenging) than conventional programming. Rather than write code (structured, if you like) through a series of events, you'll do better to start off with a co-operation diagram of the process that you want to automate [[For the newcomer, Expect ...
|435||Expect for Windows|
I've just noticed on the Activestate site that "the ActiveTcl distribution now includes Expect for Windows. A license is no longer required ....". At face value, that looks like excellent news!
One of the big uses of Tcl and Tcl/Tk is in the automation of processes / programs that are designed to ...
Examples from our training material
|e1|| Simplest ping check via expect|
|e2|| Ping via expect, echo back a value from the report|
|e3|| expect - do not grab indeterminate |
|evening|| Automated backup|
|ftp1|| First Expect example|
|ftp2|| Expect with some error checking and decisions|
|gup|| Grabbing a log file and locally analysing|
|linksandimages|| Grab a web page, report all links and images|
|plet.exp|| Expect for Windows - ping a host and guess its distance from you|
|qp|| Expect to automate a series of pings|
|weblinks|| Grab a web page and report all links|
|wuff|| Expecting from a list (regular expression)|
|xpx|| quick ping around a series of hosts|
|yap|| Expecting from a list (expect block)|
PicturesTcl and Expect - a great way to handle interaction
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
A regular task.
A possible solution.
What else is Expect?.
spawn, expect and send.
More on the expect command.
Not wanting to echo what you expected?.
Not knowing what to expect?.
Variables set by expect.
Running Expect on Windows platforms.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.