tags:

views:

289

answers:

3

I have to execute several command line executables in Windows through Java. Rather than using Runtime.exec, I thought of using Ant Tasks to do these invocations, hoping it would be a better way.

Is there any other better approach or any popular library to do this?

+5  A: 

What exactly is wrong with using Runtime.exec()? It's in the API for a good reason...

Alnitak
A: 

I have a similar situation now. I use Runtime and Process classes. They work just fine.

euphoria83
+1  A: 

Runtime.exec is the way of doing this in Java. Any other library would likely be platform specific. You'd need a very good reason not to use Runtime.exec.

I've currently got several programs that make use of this feature and it hasn't caused any trouble.

With Runtime.exec you can optionally block while waiting for the call to complete. You can capture return codes and anything the command line program writes to the console. And I'm sure there are many other features, those are just the ones that were useful to me.

And you can always have it invoke an ant task if you really want to use ant! :)

Kris