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