oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Network Test Automation with Mac OS X and Tcl
Pages: 1, 2, 3, 4

Tcl and Expect for Mac OS X

Now that you've set up your rootless environment and have your editor installed, we can fire up Tcl.

Tcl is an installed package on Mac OS X machines. However, Apple didn't include Expect, or Tk (X11 tool kit for Tcl). Don't ask why. Not a real problem though. Michael Peters has provided an excellent port of Expect 5.32 which requires Tcl 8.4a2 -- a revision different from Apple's. You'll need to download and install these two compressed packages to start using Expect.

The downloadable file is a StuffIt .hqx file. Once downloaded, the image decompresses to a mountable disk image. You will need to use the Disk Copy utility in the Applications/Utilities folder to mount the .img file.


Mounting the Tcl and Expect images

Figure 3. Mounting the Tcl and Expect images.

The mounted image is an installation package that you will need to double-click in order to start the installation. Remember, the new Tcl installation is required for the Expect installation.


The Tcl 8.4a2 folder contents

Figure 4. The Tcl 8.4a2 folder contents.

Unfortunately, the Expect and Expect Tk (the graphical user interface and toolkit) portion of the package has yet to be tackled for Mac OS X. In a network test environment, we can survive with command-line scripts. But I know how excited your manager gets when you show them a GUI application. If you were adventurous enough to port Expect Tk, or know where a working image is hiding, please let us know in the O'Reilly TalkBack section for this article. In the meantime, we're command-line constrained.

Invoking Tcl

Comment on this articleAfter having worked with Michael's Tcl examples, let us know what you think or where you got stuck.
Post your comments

Tcl is a simplistic language that is string-based. You can invoked Tcl by executing the command tclsh from your terminal or console window. A simple "Hello World!" script looks like this:

Spongebob # tclsh
% set myString "Hello World!"
Hello World!
% puts $myString
Hello World!

This code snippet demonstrates how Tcl uses the set command to assign the string value "Hello World!" to the variable myString. Assigning a "$" in front of the variable, myString, instructs the interpreter that the script is going to reference the value contained there. In this example, the string value is "Hello World!". The puts command writes the value referenced to the terminal window.

Pages: 1, 2, 3, 4

Next Pagearrow