empty - run processes and applications under pseudo-terminal (PTY) sessions and replace TCL/Expect with a simple shell-tool

SourceForge.net Logo

Common shell (sh, bash, ksh, csh, tcsh) together with standard UNIX tools like cat, grep, sed and etc can bring you all the power of full featured scripting language. In other words, you often do not need to intall and use more powerful languages as Perl or Python, etc.
Support This Project But often doesn't mean always, and one of the oldest problems was the use of Command-line interactive programs in UNIX shell-scripts. The goal of this project is to solve the problem and give an opportunity to simplify the management of interactive applications in common sh-scripts.

empty is an utility that provides an interface to execute and/or interact with processes under pseudo-terminal sessions (PTYs). This tool is definitely useful in programming of shell scripts designed to communicate with interactive programs like telnet, ssh, ftp, etc. In some cases empty can be the simplest replacement for TCL/expect or other similar programming tools because empty:

  • can be easily invoked directly from shell prompt or script
  • does not use TCL, Perl, PHP, Python or anything else as an underlying language
  • is written entirely in C
  • has small and simple source code
  • can easily be ported to almost all UNIX-like systems

Nowadays empty was successfully compiled and tested on:

download empty now!

  • FreeBSD, NetBSD, OpenBSD and macOS
  • Linux kernels (32 and 64bits)
  • SCO UnixWare 7.1.1, OpenUnix 8.0.0
  • Oracle/SUN Solaris
  • IBM AIX
  • HP-UX 11.00, 11.11, 11.23 (pa-risc, itanium)
  • Cygwin DLL-1.5.19-4 (Experimental, see README.CYGWIN)
  • OSF1 4.0, 5.1

Installation is simple: download, then ungzip and untar the source code:

	tar zxvf empty-x.y.z.tgz

If you have Linux or *BSD just run:

	make all install clean

on any other *NIX try:

	make `uname -s` all install clean
	 or
	make `uname -s`-gcc all install clean

This will compile and place empty with its manual page under /usr/local tree. Good luck and beware of bugs!


empty was written by Mikhail E. Zakharov on the basic idea of pty-4.0 Copyright (c) 1992, Daniel J. Bernstein, but no code was ported from it.

Great thanks to:

  • Aleksey Kozlov - avtolik@newmail.ru
  • Alexey Rudometov - rudometov@u-systems.ru
  • Alex Slyotov - aslyotov@gmail.com
  • Bernd Schuller
  • David Hofstee - davidh@blinker.nl
  • Dennis Schridde
  • Dmitry S. Vlasov - vlasov@quantum.ru
  • Elisender - allex_9@ngs.ru
  • Lang Qiu - qiulang@gmail.com
  • Ralf Winkel
  • Roman Gorohov - idle@idle.org.ru
  • sdio - sdio4lor @ gmail.com
  • Sergey Redin - sergey@redin.info
  • Sergey V - flexdsl@mail.ru
  • Sergey Yaroshevsky - astraserg@proc.ru
  • Sylvain DEGUT - sylvain.degut@neuf.fr
  • Vincenzo Maggio - vince.maggio@gmail.com

I express deep gratitude to Hewlett Packard AO Russia and personally to Denis Karzhavin and Andrew Kuchinsky for C110 (9000/777) workstation

empty
#!/bin/sh
empty -f -i in -o out telnet foo.bar.com
empty -w -i out -o in "ogin:" "luser\n"
empty -w -i out -o in "assword:" "TopSecret\n"
empty -s -o in "who am i\n"
empty -s -o in "exit\n"
TCL/Expect
#!/usr/bin/expect

spawn telnet foo.bar.com 
expect ogin {send luser\r}
expect assword {send TopSecret\r}
send "who am i\r" 
send "exit\r"
expect eof
Perl/expect module
#!/usr/bin/perl

use Expect;

my $exp = Expect->spawn("telnet foo.bar.com");
$exp->expect($timeout,
        [ 'ogin: $' => sub {
                     $exp->send("luser\n");
                     exp_continue; }
        ],

        [ 'assword:$' => sub {
                      $exp->send("TopSecret\n");
                      exp_continue; }
        ],
        '-re', qr'[#>:] $'
);
$exp->send("who am i\n");
$exp->send("exit\n");
$exp->soft_close();
Python/Pexpect
#!/usr/local/bin/python

import pexpect

child = pexpect.spawn('telnet foo.bar.com');

child.expect('ogin: ');
child.sendline('luser');

child.expect('assword:');
child.sendline('TopSecret');

child.sendline('who am i');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;

All the examples above show the same quick telnet session using empty and various scripting languages.








Copyright (C), 2005-2020 Mikhail E. Zakharov