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 .
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");
shell.expect("Chunder");
shell.send("exit\n");
shell.expectClose();
// 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 ...>
<dependencies>
<dependency>
<groupId>net.sourceforge.expectj</groupId>
<artifactId>expectj</artifactId>
<version>2.0</version>
<!-- Optional scope: Use ExpectJ for (unit) tests only -->
<scope>test</scope>
</dependency>
...
</dependencies>
...
</project>
If you really don't want to use Maven , try your luck at the Sourceforge download page
ExpectJ is released under the GNU Lesser General Public License 2.1 .