1

The thing is... I'm running a process with the DefaultExecutor class of org.apache.commons.exec libraries. Like this:

public class Main {

public static void main(String[] args) throws IOException, InterruptedException {

    CommandLine cmd = new CommandLine("java");
    DefaultExecutor exec = new DefaultExecutor();
    exec.setExitValue(1);
    exec.execute(cmd);
}

I need to take that output "on the run" with another thread, to log it elsewhere. What is the best way of accomplish that?

palacsint
  • 28,416
  • 10
  • 82
  • 109
Emiliano
  • 185
  • 1
  • 12

2 Answers2

1

Use a PipedOutputStream and a PipedInputStream. You can find an example here. Don't forget to close your streams.

Community
  • 1
  • 1
palacsint
  • 28,416
  • 10
  • 82
  • 109
0

You should probably look at log4j, a rather useful project from Apache. In a project I was recently working on, log4j was used to put all of the logs from various threads into one convenient file. Just make sure that you construct the logger in such as way that only one instance of it is available, and this should solve your problem.

Unfortunately, I was only an intern, and was not present when the team set up the logging system, so I can't actually help you with configuration. Luckily the project's website appears to have plenty of documentation to help you out.

smitty1110
  • 11
  • 2