I am trying to decide as to whether to use ProcessBuilder
or Commons exec,
My requirements are that I am simply trying to create a daemon process whose stdout/stdin/stderr I do not care about. In addition I want to execute a kill to destroy this process when the time comes.
I am using Java on Linux.
I know that both have their pains and pitfalls (such as being sure to use separate thread to swallow streams can lead to blocking or deadlocks, and closing the streams so not to leave open files hanging around) and wanted to know if anyone had suggestions one way or the other as well as any good resources to follow.
The ZT Process Executor library is an alternative to Apache Commons Exec. It has functionality to run commands, capture their output, set timeouts, verify program exit status etc.
I have used it a little and I find it well-designed reasonably well-documented.
Executing a command, pumping the stderr to a logger, returning the output as UTF8 string.
String output = new ProcessExecutor().command("java", "-version") .redirectError(Slf4jStream.of(getClass()).asInfo()) .readOutput(true).execute() .outputUTF8();
Its documentation lists the following advantages over Commons Exec:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With