logger.sh revision 1236:bebfcf0b68ea
152419Sjulian#!/bin/bash
252419Sjulian#
379755Sdd# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
452419Sjulian# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
552419Sjulian#
652419Sjulian# This code is free software; you can redistribute it and/or modify it
752419Sjulian# under the terms of the GNU General Public License version 2 only, as
852419Sjulian# published by the Free Software Foundation.
952419Sjulian#
1052419Sjulian# This code is distributed in the hope that it will be useful, but WITHOUT
1152419Sjulian# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1252419Sjulian# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1352419Sjulian# version 2 for more details (a copy is included in the LICENSE file that
1479755Sdd# accompanied this code).
1552419Sjulian#
1652419Sjulian# You should have received a copy of the GNU General Public License version
1752419Sjulian# 2 along with this work; if not, write to the Free Software Foundation,
1852419Sjulian# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1952419Sjulian#
2052419Sjulian# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2152419Sjulian# or visit www.oracle.com if you need additional information or have any
2252419Sjulian# questions.
2352419Sjulian#
2452419Sjulian
2552419Sjulian# Usage: ./logger.sh theloggfile acommand arg1 arg2
2652419Sjulian#
2752419Sjulian# Execute acommand with args, in such a way that
2852419Sjulian# both stdout and stderr from acommand are appended to
2952419Sjulian# theloggfile.
3052419Sjulian#
3152419Sjulian# Preserve stdout and stderr, so that the stdout
3252419Sjulian# from logger.sh is the same from acommand and equally
33130131Sru# for stderr.
3452419Sjulian#
3552419Sjulian# Propagate the result code from acommand so that
36130131Sru# ./logger.sh exits with the same result code.
3752419Sjulian
3879537Sru# Create a temporary directory to store the result code from
3952419Sjulian# the wrapped command.
4052419SjulianRCDIR=`mktemp -dt jdk-build-logger.tmp.XXXXXX` || exit $?
4152419Sjuliantrap "rm -rf \"$RCDIR\"" EXIT
4254980SarchieLOGFILE=$1
4352419Sjulianshift
4452419Sjulian(exec 3>&1 ; ("$@" 2>&1 1>&3; echo $? > "$RCDIR/rc") | tee -a $LOGFILE 1>&2 ; exec 3>&-) | tee -a $LOGFILE
4552419Sjulianexit `cat "$RCDIR/rc"`
46130131Sru