Version 16 of Expect for languages other than Tcl

Updated 2010-09-19 21:13:52 by Cameron

When Don Libes first created Expect, he assumed other languages would incorporate bindings relatively quickly. It's a testimony to the package's polish that no substantial efforts were made with other language bindings for many years; it's because his Expect has seemed so perfect, not for any lack of need other languages have.

By 2000, though, unripe Expect-like facilities were available for such languages as Perl and Python. In contrast to the situation for Tk, other languages have not created Expect modules by linking against Don's libraries; instead, they've written "from scratch" in more language-specific fashion.

Python has several Expect initiatives (just as it has a plethora of Web servers, GUI toolkits, and so on). Most advanced appears to be the pure-Python Pexpect [L1 ].

Expect.pm [L2 ]

ruby-expect [L3 ]


How does the programming power of Tcl/Expect compare to that of the Expect modules of other languages? This comparison is far more difficult to explain than might first appear; full understanding involves several subtleties. Here are the highlights:

  • Tcl/Expect can do anything the others can do.
  • Tcl/Expect is more mature, and, in particular, better-behaved across a range of Unixes.
  • Tcl/Expect has exceptionally interesting and powerful channel-processing capabilities, and event-oriented ones in particular, that other Expects don't even attempt. However, only a small minority of Expect programmers ever use these. In fact, many (many) programmers make no more use of Expect than they would of the corresponding telnet module (telnetlib for Python).

Don himself [...] writes on this question [L4 ] in response to "What is it that Expect can do that Pexpect can't".

[More detail.] [See essay on "Most programmers don't know what Expect can do for them".]

Because of its channel abstraction, Expect can interact with multiple processes quite easily. That has been more cumbersome or even infeasible with Expect extensions available for other languages.


Summary: Expect is generally "better" in the usual ways programmers understand that, compared to Expect-like modules for other languages, in:

  • the maturity of its pty management (there's a lot of OS-specific hair here);
  • interact
  • its facility with multiple managed processes or other I/O streams.
  • the book BOOK Exploring Expect
  • the on-line tutorials [...]
  • all the examples in the distribution and book

Category Expect