chickadee » tcl-expect


Chicken scheme binding to libexpect

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications.


Aydar Zarifullin



Note: Windows is not supported.


Debian-based system

1. Install the dependencies

apt install tcl-dev tcl-expect-dev

2. Tell the compiler where the Tcl header files are located by setting the CSC_OPTIONS environment variable


3. Install this egg

chicken-install tcl-expect

Arch-based system

1. Install the dependencies

pacman -S expect

2. Determine the Expect version

expect -version

3. Create a symlink

ln -s /usr/lib/expect<version>/libexpect<version>.so /usr/lib/

Where <version> is the number from the previous step

4. Install this egg

chicken-install tcl-expect


call-with-process-io cmd procprocedure

Forks a new process and executes cmd via Bourne shell then call proc which should be a procedure of three arguments: the input, output, and PID of the sub-process.

Note: The input and output ports will not be closed if proc raises an error

While it is possible to use read-line to read information from a process spawned by call-with-process-io, more convenient function are provided.

expect in-port patternprocedure

The function waits until the output from a process matches the pattern, a specified time period has passed, or an EOF is seen. The first argument to the function is an in-port the second argument is a Tcl glob-style string pattern.

Returns one of the following values

  • ok
  • eof
  • timeout
  • fullbuffer
set-timeout secsprocedure

Sets timeout for expect function. The default timeout period is 10 seconds. A value of -1 disables a timeout from occurring. A value of 0 causes the expect function to return immediately.


(import (prefix tcl-expect #:expect) (chicken io))

(expect:call-with-process-io "bc"
                             (lambda (in out pid)
                              (expect:expect in "`warranty'")
                              (display "20+12\n" out)
                              (read-line in)
                              (read-line in)
                              (read-line in)
                              (display (read-line in))))



Copyright 2021 Aydar Zarifullin.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A full copy of the GPL license can be found at <>.

Contents »