Embedding command line in Java applications

Are you tired of issues with Runtime.getRuntim().exec()?

I was.

So I decided to create a small library to handle all the issues. Features include:

  • It's easy to redirect stdin, stderr and stdout to appropriate Java Readers and Writers, so you can now embed operating-system processes inside your applications.
  • It's very easy to cancel a running process, by using the Future<Integer> interface.
  • Automatically handles pipipng process streams into Java streams (and viceversa).
  • Runs well in Linux and Windows. Probably runs well in Solaris and MacOSX too (haven't tried yet though)
  • You can specify a working directory for the running process.
  • Very small library (just one final class and two interfaces).

Sources and binaries available.

How to use?

You can see the Javadoc. Basic usage is as follows:

// Obtain a process executor
ProcessExecutor executor =

// Launch the process
Future<Integer> process = executor.execute(
   ProcessInputOutput.DEFAULT, null, "/bin/ls -ali");

// If you want to kill the process write:
process.cancel( true );

// To get the exit status of the process use:
System.out.println( process.get() );

Now, that's easy, isn't it?


This software is licensed under the GNU GPL v2.0.