This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC compiler cannot create executables.


On Fri, 6 Dec 2002 12:05:24 -0500 (EST) Igor Pechtchanski <pechtcha@cs.nyu.edu> wrote:

> FWIW, there's also apparently a cygwin port of 'script':
> http://cygwin.com/ml/cygwin/2002-09/msg01371.html

It's also easy to redirect STDOUT and STDERR to a file.  I found myself
doing it often enough that I wrote a script to do it for me.  It needs a
log/ directory in the current directory or one of its parents.

#!/bin/bash
# Find nearest log directory and tee log command output to a file there
# set -xv

log=""
usage() {
   if [ 1 -le $# ]; then $rc="$1"; shift; else rc=0; fi
   basename=$(basename "$0")
   msg=\
"Send stdout and stderr to a log file
   If no log file is specified, search for the nearest log/ directory in ./,
   ../, ../../ until / is reached and generate a file name based on the command
   name and the current date and time.
syntax: $basename [opt] cmd [arg]...
Opt:
   -l log = Log file ($log)
Arg:
   cmd = Command to execute
   arg = Options and arguments to cmd"

   while [ 1 -le $# ]; do
      if [ 0 = "$rc" ]; then echo "$1"; else echo "$1" >&2; fi
      shift
   done
   if [ 0 = "$rc" ]; then echo "$msg"; else echo "$msg" >&2; fi
   exit $rc
}

while getopts ':hl:' OPT
do
   case $OPT in
      l) log="$OPTARG" ;;
      h) usage 0 ;;
      *) usage 1 "Invalid Option: -$OPTARG"  ;;
   esac
done
if [ 1 -lt $OPTIND ]; then shift $(expr $OPTIND - 1); fi

# Make sure there is a command name
if [ 1 -gt $# ]; then
   echo "No command name"
   exit 1
fi
cmd=$(basename "$1")

# Find log directory and build log file name
if [ -z "$log" ]; then
   logbase="$PWD"
   while :; do
      if [ "/" = "$logbase" ]; then
         echo "Log directory not found under $PWD"
         exit 1
      fi
      if [ -d "$logbase/log" -a -w "$logbase/log" ]; then break; fi
      logbase=`dirname "$logbase"`
   done
   dt=$(date +%y%m%d_%H%M)
   log="$logbase/log/$cmd-$dt.log"
fi
echo "Log file: $log"
touch "$log"
echo "Dir: '$PWD'"   >> "$log"
echo "Command:" "$@" >> "$log"

"$@" 2>&1 | tee -a "$log"
echo "Log file: $log"

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]