ProcessUtils

This class with its supporting classes provides a set of very easy interfaces for running external command-line programs from Java, inspired by the TCL exec facility. It is also similar in use to Perl backtick command execution.

Available information:

Example Usage

A very common form of use of ProcessUtils.exec is to run an external program, passing in command-line arguments and receiving the output back as a string. For example on most Unix-like systems, to receive information about space usage on file systems you can use the "df" command. With ProcesUtils this is:

  String fileStats = 
    ProcessUtils.exec(new String[]{"df"});

With exception handling, the same example could become something more like this:

  String fileStats = null;
  FileSystemInfo record = new FileSystemInfo();
  try {
    fileStats =  ProcessUtils.exec(new String[]{"df"});
    record.parseUnixFileStats(fileStats);
  } catch(ProcessUtils.Exception ex) {
    // Log exception, alternate processing, etc.
  }