1

AFAIK, one can run a command line executable from Java using Runtime. And even get error code with processes WaitFor(). But how can I read executables output? Both stdout and stderr?

1 Answer 1

1
Runtime tr = Runtime.getRuntime();

try {
    Process p = tr.exec("c:\\a.bat");
    InputStream err = p.getErrorStream();
    InputStream std = p.getInputStream();
    //TODO here we go!
} catch (IOException e) {
    e.printStackTrace();
}
Sign up to request clarification or add additional context in comments.

1 Comment

This does not work. The correct solution uses at least one more thread, two is better, to handle the asynchronous nature of co-processes.

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.