I have a JVM app that is being run from a bash script. I would like for the app to return an output to the script, so that the script can use it as a parameter for other commands.
One suggestion I've read is to use System.out.print on the desired output. However, my application does a significant amount of logging using log4j. It also invokes other libraries which also log other info as well. If my bash-script tries to read from stdout, wouldn't it read all of those log-outputs as well?
Another option I thought of is:
- The script passes in a
/tmp/${RANDOM}.outfile-path to the application - The JVM application writes the desired output to the specified file
- The script reads the value off the specified file, once the application has finished running
The above approach seems more cumbersome, and makes certain assumptions about the system's file-system and write-permissions. But it's the best option I can think of.
Is there a better way to do this?