Problem with call of Java Programm & return code handling & output to several streams.

Hello Everybody,
thanks in advance for spending some time in my problem.
My problem is this:
I want to call a java-Programm out of my shell skript, check if die return code is right, and split the output to the normal output and into a file.

The following code doesn't work right, because in the if construct it checks if de 'tee' command did work.

if ( java -cp .:./lib/*.jar:./lib/*.jar:./lib/*.jar:./lib/*.jar *.*.* $*  | tee -a $PathToLog )

could you igamine what solution could solve my problem? (the java command itself works, the stars are only for anonymize)

thanks a lot

danifunny

This should work, though the processing would happen before displaying the output:

if java ... > TEMP.FILE; then
    # Process success
fi
cat TEMP.FILE | tee -a $PathToLog
rm -f TEMP.FILE

Or this would keep things in order:

java ... > TEMP.FILE
result=$?
cat TEMP.FILE | tee -a $PathToLog
rm -f TEMP.FILE
if [ $result = 0 ]; then
    # Process success
fi

Or, if the processing produces no output, you might do this:

if java ... ; then
    # Process success
fi | tee -a $PathToLog

This works - after a first test - fine for me, the 2 other solutions don't fit my needs for this script, but maybe i'll use them another time ;). Thanks a lot!

After some own research today, i came across this solution:

set -o pipefail

if ( java .... ) | tee -a $PathToLog
then  # Process succes
fi

Can you think of what solution of these two would be the best one?

thanks and greets
danifunny