-1

I have an application A which writes a stdout message. Now i will build a second application B which reads the stdout from A.

I don't want create a file, the message will be write in the console and should be read from console.

I know, that i have some possibilities to read from console (Scanner, System.console(), BufferedInputstream), but how can i catch the stdout from another application?

HaDo
  • 1

2 Answers2

0

You can try communication through sockets. This guide seems useful http://cs.lmu.edu/~ray/notes/javanetexamples/

0

If your program B executed program A (either through ProcessBuilder.start() or System.exec()) you have a Process instance. Then you can use Process.getInputStream() to obtain an input stream which is connected to program A's standard output stream.

Otherwise, there is no platform-independent way to obtain the other program's catch the other program's output. You will need to use some other form of communication.

Hoopje
  • 12,677
  • 8
  • 34
  • 50
  • Thx for your the note. Unfortunately B is not executed A. What form of communication would you recommend ? – HaDo Dec 14 '18 at 10:19