#! /usr/bin/ksh

USAGE="USAGE: redirect_cmd [ -both ] OUTPUT_FILE CMD [ARG]... 
	Execute the command CMD with its arguments ARG... and 
	re-direct the output to OUTPUT_FILE.

	If -both is specified, then stderr is also re-directed
"

# echo "The command arguments are: $*"

# Process parameters
  
  BOTH=FALSE
  if [ $# -lt 2 ]
  then
    echo "$USAGE" >&2
    exit
  fi
  if [ $1 = "-both" ]
  then
    BOTH=TRUE; shift
  fi
  OUTPUT_FILE="$1"; shift

# Do it
  
  if [ "$BOTH" = "TRUE" ]
  then
    "$@" > "$OUTPUT_FILE" 2>&1
  else
    "$@" > "$OUTPUT_FILE" 
  fi
