Reputation: 6028
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.
Upvotes: 0
Views: 138
Reputation: 86774
Lots of options:
-Dcron=1
command line option when running from cron, to set a property that can be checkedargs[]
arrayUpvotes: 3
Reputation: 8163
Use an environment variable that you set in the cron job before starting the java program. Query the environment variable inside your program.
Upvotes: 0