Imagine a bacon-wrapped Ferrari. Still not better than our free technical reports.
Why repeat activities manually when you could spend much more time and effort to create a process library instead?
This is a question we’ve been asking ourselves lately. As our company and engineering team grows, we’ve found that different projects have somewhat similar needs when it comes to libraries. Whenever this happens and we think that the library can be useful for the rest of the Java world, we open-source it.
So, without further ado let me introduce you to Yet Another Process Library for Java (similar to our YAZLJ). It is written in Java for Java and is meant to manage processes that you launch from your own programs.
Let me show you a quick example. In order to find out the version of the Java executable found in the path you would have the following line in your program.
new ProcessExecutor().command("java", "-version").execute();
You’re probably thinking, why would I need yet another process library? I’ve already got the JRE standard API library and the Apache Commons Exec? Well, yeah but when you use them and you use them heavily you discover writing lots of helpers to get rid of the boiler plate. Maybe even extending them to get more out of them. This is what happened over here. I’ll outline some of the features that the library provides on top of the other choices I mentioned.
- Improved handling of streams
- Reading/writing to streams
- Redirecting stderr to stdout
- Improved handling of timeouts
- Improved checking of exit codes
- Improved API
- One liners for quite complex usecases
- One liners to get process output into a String
- Access to the Process object available
- Support for async processes ( Future )
- Improved logging with SLF4J API
- Support for multiple processes
The project is hosted at GitHub, the CI is at Travis. The project page has tons of examples to get you started, the 1.4 release is available from Maven central so you should be all good to go. Take the library for a spin and let us know what you think in the comments section below, or ping me @toomasr :-)