Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
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 coverage if it's required. For the Tk toolkit, we also include a brief demonstration on the main course, but will then add an extra day or two - a whole extra course - for people who need it. That's because Tk includes a very large number of extra commands and facilities, whereas expect adds a great deal in a few extra commands.

This week, expect is something of a side issue - so a brief demo at the end of yesterfay afternoon was all that was needed. I used the example of wishing to check a series of hosts (sequentially) with ping, and report back on the round-trip time to each. Full source code at [here]

expect is Tcl ... with extra commands, so a foreach loop through a series of hosts is the natural way to test each host in turn without repeating code:

  foreach mysite {www.wellho.net wellho.net www.wellho.co.uk www.firstgreatwestern.info} {

Within each itereation, we start off a ping progess through the spawn command:

  spawn ping -c 3 $mysite

and wait for reply text to include the words "round-trip" which comes late in the response:

  expect "round-trip"

We then use a regexp to extract the vital data we want to report froma everything that expect has dumped into a buffer thats avaulable to us, and report it withing a puts command:

  regexp {time=([0-9]+\.[0-9]+)} $expect_out(buffer) all trip
  puts "$mysite came back with a trip time of $trip"


Result?

  munchkin:tclmay11 grahamellis$ expect xpx
  www.wellho.net came back with a trip time of 21.070
  wellho.net came back with a trip time of 164.911
  www.wellho.co.uk came back with a trip time of 18.176
  www.firstgreatwestern.info came back with a trip time of 30.522
  munchkin:tclmay11 grahamellis$

As always, the devil is in the detail; my program will fail if any of the hosts isn't reachable doesn't respond, and I could add code to deal with that - the facilities are there. However, that would muddy the first training example, and in any case if the program's run and fails that's an indication in its own right that you have a problem in this case.

Tcl (and expect) course details - [here].
(written 2011-05-11)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T050 - Tcl/Tk - Tcl, Tcl/Tk and Expect - General
  [4616] Still teaching Tcl in 2016? - (2016-01-06)
  [4460] Using Object Oriented Tcl and the Tk toolkit together - real life example - (2015-03-12)
  [4434] Public training courses - upcoming dates - (2015-02-21)
  [4206] Writing the perfect program in Tcl? - (2013-11-13)
  [3192] Tcl - Some example of HOW TO in handling data files and formats - (2011-03-04)
  [2681] Tcl - a great engineering language - (2010-03-17)
  [2504] Learning to program in ... - (2009-11-15)
  [2474] Using Tcl and Expect to automate repetitive jobs - (2009-10-24)
  [2429] Tcl scripts / processes on a web server via CGI - (2009-09-27)

T211 - Tcl/Tk - What is Expect? Why use it?
  [4678] Expect with Ruby - a training example to get you started - (2016-05-18)
  [4405] Backup procedures - via backup server - (2015-01-24)
  [3572] Adding Expect on top of Tcl - what is it and where can I get a training course to learn about it? - (2012-01-08)
  [3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)
  [2489] Parallel Pinging, using Python Threads or Expect spawn lists - (2009-11-02)
  [1602] Automating processes through Expect - (2008-04-05)
  [1531] Expecting a item from a list of possibles - (2008-02-04)
  [1469] Curley brackets v double quotes - Tcl, Tk, Expect - (2007-12-12)
  [1411] Buffering of inputs to expect, and match order - (2007-10-27)
  [1409] What is Expect? - (2007-10-26)
  [1174] Installing Tcl and Expect on Solaris 10 - a checklist - (2007-05-02)
  [1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
  [435] Expect for Windows - (2005-09-04)
  [286] Automating regular manual procedures - (2005-04-21)


Back to
Extracting data from a string / line from file - Tcl
Previous and next
or
Horse's mouth home
Forward to
Exceptions - Tcl style
Some other Articles
Changes (and no changes) at Melksham bus stops
New Camera - very first picture, and next from first films
Random Questions ...
Exceptions - Tcl style
Should we cover expect and/or Tk on our public Tcl courses?
Extracting data from a string / line from file - Tcl
What to do in the evening during a Tcl course
The juggler
The future of canal management and charities - Kennet and Avon Canal bias
Does Well House Manor Hotel in Melksham offer lots of discounts?
4747 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3286_Sho ... rses-.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat