I\'m trying to capture output of an external program using java but I can\'t.
I have the code to show it, but not to put it into a variable.
I will use, for
Use Apache Commons Exec, it will make your life much easier. Check the tutorials for information about basic usage. To read the command line output after obtaining an executor
object (probably DefaultExecutor
), create an OutputStream
to whatever stream you wish (i.e a FileOutputStream
instance may be, or System.out
), and:
executor.setStreamHandler(new PumpStreamHandler(yourOutputStream));