Wednesday, March 16, 2011

Running external commands from Java

I am not a big fan of Runtime.exec for running commands via Java because there are so many fine points to take into account that running one or two simple commands requires the creation of an entire robust ecosystem. And if I ever have to repeat the process in a different codebase then writing the code again from scratch is very cumbersome.

One fine day I said to myself: Someone's got to have already written and shared these fail-safes in open-source ... right?

My search led me to commons-exec and I was thrilled! The apache website tutorial is not very enlightening about the API itself. Instead, it is this blog entry that fully allows one to understand and utilize the power of commons-exec. But an example of how to capture user-input using commons-exec is still missing from the web.

Also I ran across a library provided by Maven as part of their cookbook for maven plugin developers. I haven't experimented with it enough to talk about it but its out there.

0 comments:

Post a Comment