Capturing the system.out messages from another process

Yahwho :

I have a JVM(1) which launches JVM(2). I want to be able to monitor the System.out.println() calls from JVM(2) in JVM(1).

GhostCat salutes Monica C. :

The straight forward way would be:

  • JVM A does a system command to start JVM B
  • JVM A then reads all output from B

See here for how to do that (in essence, there is no difference between calling java SomeClass ... or any other command that then writes to stdout/stderr).

If your two JVMs get started independently, then the only option left would be that the "start command" of B redirects all output into a file. And then, depending on the OS, you can only hope that the other JVM sees all updates to that file in a timely manner.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=90594&siteId=1