Thursday, February 18, 2010

Expect and windows xp

[if you know about Expect, you can jump your interested area]


In wikipedia, about expect "Expect is a Unix automation and testing tool, written by Don Libes as an extension to the Tcl scripting language, for interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, ssh, and others. It uses Unix pseudo terminals to wrap up subprocesses transparently, allowing the automation of arbitrary applications that are accessed over a terminal. With Tk, interactive applications can be wrapped in X11 GUIs."

In simple words, Expect is very powerful scripting language to test complex protocol. Mostly used for conformance testing in networked environment. Expect can send the data across network and validate results with predefined values. For more details use official expect website @ Working with expect is fun in windows environment.

Need of Expect in Windows
Now, let's talk about the need of Expect in windows. Most of us have windows environment at work location (due to any reason). And, it is not worth to set up linux environment for Expect only. Moreover, with small steps, it is possible to set up expect on windows environment too.

Steps to start expect on Windows
So, follow following simple steps and your expect script will work as charm :)
  1. Download Active Tcl from
  2. Install (Typically @ c:/Tcl/ directory)
  3. Go to Bin directory in Command prompt (Start > Run > commad > cd c:\Tcl\bin)
  4. (only required if you use proxy) teacup proxy (e.g. teacup proxy 8080)
  5. Instruct teacup to install Expect by teacup install Expect
  6. DONE!
Convert Expect file in windows format
Now we have expect installed and we need to convert expect file into windows format. which is infect more simple. It is optional but good idea to convert extension to .tcl.

We need to add following lines @ beginning of expect file.
# \
exec tclsh "$0" ${1+"$@"}
package require Expect
Running expect file in windows
Go to command prompt and navigate to folder where you kept your expect script.
Run using tclsh85.exe file as follows.

c:\tcl\bin\> tclsh85 myscirpt.tcl

Some useful notes
It is possible to invoke external command. Use spawn
e.g. spawn ssh
(Note: To run above ssh requires. ssh can be installed as a part of openssh (free))
send -- "someting\r" (Similar to, send something and "Enter")
expect -- ">" (Similar to , expect (wait) for > to come)
Some more expect examples are at