0

I have a command line Java program which i unfortunately cannot modify for certain integrity reasons, I am providing a GUI for this program and i got it all covered except that i am unable to provide notifications about completion of processes to the user as the program prints data to command line using System.out.println() , I designed the UI using net beans and it resides in a separate file , so how can i do this..?

1 Answer 1

3

Are you using Runtime.exec to execute the program? Then you can get the output stream as well like this:

Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("java yourOtherProgram.jar");
InputStream stdin = proc.getInputStream();

If you're calling some method directly, you could redirect System.out like this:

PrintStream out = ...;
PrintStream err = ...;

System.setOut(out);
System.setErr(err);

ThatOtherProgram foo = new ThatOtherProgram();
foo.main(new String[0]);

EDIT

You could then use the Scanner to scan the input and do something with it.

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

2 Comments

Thanks for your help.. I re implemented the program using runtime.exec but i am still working on how to dynamically provide notifications based on the stream.. Thank you for your effort..
You could use the Scanner class to do that.

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.