0

I have a swing java project, call it "A", and I have another not-swing, only backend project, which has no frames and panels, only run in background, and prints texts to command line with System.out.println, call it "B".

What I want is:

  1. start "B" from "A"
  2. monitor "B" in "A": if "B" prints something to the command line with System.out.println, it should be visible in a TextArea of "A"
  3. if "B" is finished, "A" should know about it

I already know that I can start the jar from another jar by these lines:

Process ps=Runtime.getRuntime().exec(new String[]{"java","-jar","A.jar"});
ps.waitFor();

or:

Process proc = new ProcessBuilder("java", "-XMx512M", "-jar", "MainJar.jar").start();
int result = proc.waitFor();

But how to monitor the started jar? Can anyone help me with an easy example? Thank you!

victorio
  • 6,224
  • 24
  • 77
  • 113
  • 1
    I am not sure how to do it, but you can't just print to the command line. You'll have to pass messages between the processes to do what you're speaking about asynchronously. They'll have to use a port on the computer or you could write to a file and the other process can monitor it some how. I hope that helps. – Craig Aug 17 '15 at 09:23
  • There's a quite comprehensive answer to a similar question here: http://stackoverflow.com/questions/3643939/java-process-with-input-output-stream – Burleigh Bear Aug 17 '15 at 09:56

1 Answers1

1

Have you tried Java Management Extensions (JMX)?