annotate discard_stderr_wrapper.sh @ 4:0a872e59164c

Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
author Lance Parsons <lparsons@princeton.edu>
date Wed, 25 May 2011 19:33:40 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
1 #!/bin/sh
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
2
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
3 # STDERR wrapper - discards STDERR if command execution was OK.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
4
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
5 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
6 # This script executes a given command line,
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
7 # while saving the STDERR in a temporary file.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
8 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
9 # When the command is completed, it checks to see if the exit code was zero.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
10 # if so - the command is assumed to have succeeded - the STDERR file is discarded.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
11 # if not - the command is assumed to have failed, and the STDERR file is dumped to the real STDERR
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
12 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
13 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
14 # Use this wrapper for tools which insist on writting stuff to STDERR
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
15 # even if they succeeded - which throws galaxy off balance.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
16 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
17 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
18 # Copyright 2009 (C) by Assaf Gordon
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
19 # This file is distributed under the BSD license.
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
20 #
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
21 # Modified by Lance Parsons (2011)
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
22 # Echo STDERR to STDOUT if return code was 0
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
23
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
24 TMPFILE=$(mktemp -t tmp.XXXXXXXXXX) || exit 1
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
25 #CWD=`pwd`
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
26 #DIRECTORY=$(cd `dirname $0` && pwd)
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
27 #cd $DIRECTORY
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
28 "$@" 2> $TMPFILE
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
29
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
30 EXITCODE=$?
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
31 # Exitcode != 0 ?
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
32 if [ "$EXITCODE" -ne "0" ]; then
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
33 cat $TMPFILE >&2
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
34 else
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
35 # echo "Testing STDOUT"
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
36 cat $TMPFILE >&1
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
37 fi
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
38 rm $TMPFILE
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
39 cd $CWD
0a872e59164c Added discard_stderr_wrapper.sh script to catch report and redirect to stdout
Lance Parsons <lparsons@princeton.edu>
parents:
diff changeset
40 exit $EXITCODE