ohair@494: #!/bin/bash ohair@425: # ohair@425: # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. ohair@425: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohair@425: # ohair@425: # This code is free software; you can redistribute it and/or modify it ohair@425: # under the terms of the GNU General Public License version 2 only, as ohair@425: # published by the Free Software Foundation. ohair@425: # ohair@425: # This code is distributed in the hope that it will be useful, but WITHOUT ohair@425: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohair@425: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohair@425: # version 2 for more details (a copy is included in the LICENSE file that ohair@425: # accompanied this code). ohair@425: # ohair@425: # You should have received a copy of the GNU General Public License version ohair@425: # 2 along with this work; if not, write to the Free Software Foundation, ohair@425: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohair@425: # ohair@425: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@425: # or visit www.oracle.com if you need additional information or have any ohair@425: # questions. ohair@425: # ohair@425: ohair@425: # Usage: ./logger.sh theloggfile acommand arg1 arg2 ohair@425: # ohair@425: # Execute acommand with args, in such a way that ohair@425: # both stdout and stderr from acommand are appended to ohair@425: # theloggfile. ohair@425: # ohair@425: # Preserve stdout and stderr, so that the stdout ohair@425: # from logger.sh is the same from acommand and equally ohair@425: # for stderr. ohair@425: # ohair@425: # Propagate the result code from acommand so that ohair@425: # ./logger.sh exits with the same result code. ohair@425: ohair@425: # Create a temporary directory to store the result code from ohair@425: # the wrapped command. erikj@445: RCDIR=`mktemp -dt jdk-build-logger.tmp.XXXXXX` || exit $? erikj@445: trap "rm -rf \"$RCDIR\"" EXIT ohair@425: LOGFILE=$1 ohair@425: shift erikj@445: (exec 3>&1 ; ("$@" 2>&1 1>&3; echo $? > "$RCDIR/rc") | tee -a $LOGFILE 1>&2 ; exec 3>&-) | tee -a $LOGFILE erikj@445: exit `cat "$RCDIR/rc"`