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?

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

I know how to log it, but I need to get the String from the console before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.