Package org.marketcetera.util.exec

Process execution.

Process execution in Java is harder than it seems. ProcessBuilder simplifies some of the necessary steps, but still does not address several aspects of process management that this package addresses. Specifically, Exec provides execution of a process with the following enhancements:

  • Routing/capture of its standard output and error streams. Both streams are always routed to the same destination Disposition, which can be in-memory capture, or redirection to the parent process standard output or error stream (both child streams go to the same parent stream).

  • Exit code capture. The exit code of the child process is captured (always) alongside the process output (if in-memory disposition was elected) in ExecResult.

  • Synchronous execution. The parent blocks while waiting for the child to complete. The package assumes children do not need any data to be provided in their standard input steam, or else the parent may wait indefinitely on a blocked child.

  • Setting working directory. The working directory of the child can be set before the child process is started.

All of the above functionality is available via simple static calls into methods of Exec.