Demand:
It comes from a business implementation that requires a shell script to tune the Java program, and the ability to get the return value inside java.
Ideas:
As is known to call Java through the shell, it is definitely through the Java-jar Xxx.jar command to call a jar of a main function, if you want to return the value, the best way is certainly System.out.println ("return value"), Can be analogous to how the log is printed. Or you can use echo $ to get the value returned to the OS. Since the way to log, then of course, through the > method into a log file, how to store to log files and can be displayed on the screen?
There's a tee command in Linux,
Function Description: Reads the standard input data and outputs its contents to a file. Language method: Tee [-ai][--help][--version][file ...] Supplemental NOTE: The tee instruction reads data from a standard input device, outputs its contents to a standard output device, and saves it as a file (a new file is created when the file does not exist). Parameter :-A or--append attached to the back of the existing file rather than overwriting it. The interrupt signal is ignored by the-i-i or--ignore-interrupts . --help online Help. --version Displays version information.
Detailed. SH is as follows:
#sh./install.shclaspath= '. /lib/*:.. /plugins/* '. /jre/bin/java-dbsp-mysql-dlogback.configurationfile=. /conf/logback.xml-dbase.dir=. /-CP $claspath Com.broada.bsp.mysql.TestAvgs |tee run.log 2 &
Linux command--tee redirect to file and print to screen