On a Redhat OS, I have a script that launches a Java program. This script can be started from the command line but is launched (periodically) by crontab as well.
Within this program, I need to know how the program was started. This because the output is written either to STDOUT (if started from the command line) or in a logfile (if launched by crontab).
First I thought I could use System.console()
.
The problem is that this method returns null
also if the program was started from the command line but with STDIN and/or STDOUT redirected.
Any idea how to resolve this?
I tried How can I check if a Java program's input/output streams are connected to a terminal? but that doesn't answer my question.