chickadee » tcl-expect

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.

Author

Aydar Zarifullin

Repository

https://github.com/iZarif/ckn-expect

Dependencies

Note: Windows is not supported.

Installing

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

CSC_OPTIONS="-I/usr/include/tcl"

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/libexpect.so

Where <version> is the number from the previous step

4. Install this egg

chicken-install tcl-expect

Documentation

call-with-process-io cmd procprocedure

Forks a new process and executes cmd 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 pattern [timeout 10])procedure

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 the optional third argument sets timeout. The default timeout period is 10 seconds. A value of -1 disables a timeout from occurring. A value of 0 causes the function to return immediately.

Returns one of the following values

  • ok
  • eof
  • timeout
  • fullbuffer

Example

(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))))

Changelog

License

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 <http://www.gnu.org/licenses/>.

Contents »