J. Lewis Muir > Software > Procrun

Procrun (Process Runner) is a pure Java library for running an operating system process and obtaining its exit status and what it writes to its standard output and standard error streams.

The ProcessBuilder and Process classes from the java.lang provide an interface for running a process, but there are a number of additional things that must be done to correctly run a process and read its output. Procrun tries to fill this gap.

Procrun provides the following features:

Example 1: Run the uptime program by creating a ProcessRunner instance

ExecutorService service = null;
try {
  service = Executors.newSingleThreadExecutor();
  ProcessBuilder builder = new ProcessBuilder("uptime");
  ProcessRunner runner = new ProcessRunner(builder);
  Future<ProcessRunnerResult> future = service.submit(runner);
  ProcessRunnerResult result = future.get();
} finally {
  if (service != null) service.shutdownNow();

Example 2: Run the uptime program using a static convenience method

ProcessBuilder builder = new ProcessBuilder("uptime");
ProcessRunnerResult result = ProcessRunner.run(builder);

Example 3: Run the uptime program reading its standard output into an 80 byte fixed-size buffer

ProcessBuilder builder = new ProcessBuilder("uptime");
InputStreamConsumerFactory factory;
factory = FixedSizeBufferInputStreamConsumer.newFactory(80);
ProcessRunnerResult result = ProcessRunner.run(builder, factory);



Release Notes