ExpectJ can be used for automating interaction with either a process (through stdin / stdout) or a telnet session. It is a Java implementation of the Unix expect utility.

Basic usage

The following snippet can be used for running a short shell session. Try putting something like it in a unit test for example:

// Create a new ExpectJ object with a timeout of 5s
ExpectJ expectinator = new ExpectJ(5);

// Fork the process
Spawn shell = expectinator.spawn("/bin/sh");

// Talk to it
shell.send("echo Chunder\n");

// Done!

On timeout a TimeoutException will be thrown.

More usage information is in the javadocs.


Don't. Use Maven. Put the following dependency in your pom.xml:

<project ...>

      <!-- Optional scope: Use ExpectJ for (unit) tests only -->

If you really don't want to use Maven, you can download jar files directly from Apache's Maven repository


First of all, you need to install Bzr to get the latest sources.

Then you need Maven to build. At the time of this release Maven 2.2.1 was used for upstream development, other versions may work fine as well.

To get the sources:

bzr branch bzr://expectj.bzr.sourceforge.net/bzrroot/expectj/trunk

To create an Eclipse project:

cd trunk
mvn eclipse:eclipse

To run the unit tests:

mvn test

To commit any changes to your local branch (don't forget to "bzr add" any new files first):

bzr ci

To generate a patch with your checked in changes:

bzr send -o expectj.patch

To update your branch with the latest changes from upstream:

bzr merge
bzr ci

To see what changes you have that upstream doesn't and the other way around:

bzr missing


ExpectJ is released under the GNU Lesser General Public License 2.1.