I'm writing a program in Java which relies on a pre-compiled third party JAR residing in the same directory as mine. At runtime, my program checks if this file exists, then downloads it if it doesn't. Its main class is then executed. However, the spawned program prints a large amount of text directly to the console. Is there any way to 'capture' (and therefore hide) this output from stdout
and return my own input directly from my parent application to stdin
? I would ideally like the child program to reside inside the same JVM, so I would like to avoid any version of Runtime.exec()
.
Copyright Notice:Content Author:「MTCoster」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15645387/capture-io-of-spawned-program-in-java