annotate wrapper.sh @ 19:cc270db37d33 draft

Directories re-arranged
author Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
date Sat, 06 Oct 2012 21:50:39 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
1 #!/bin/sh
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
2
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
3 # STDERR wrapper - discards STDERR if command execution was OK.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
4
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
5 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
6 # This script executes a given command line,
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
7 # while saving the STDERR in a temporary file.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
8 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
9 # When the command is completed, it checks to see if the exit code was zero.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
10 # if so - the command is assumed to have succeeded - the STDERR file is discarded.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
11 # if not - the command is assumed to have failed, and the STDERR file is dumped to the real STDERR
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
12 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
13 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
14 # Use this wrapper for tools which insist on writting stuff to STDERR
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
15 # even if they succeeded -
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
16 # which throws galaxy off balance.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
17 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
18 #
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
19 # Copyright 2009 (C) by Assaf Gordon
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
20 # This file is distributed under the BSD license.
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
21
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
22 TMPFILE=$(mktemp) || exit 1
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
23
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
24 "$@" 2> $TMPFILE
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
25
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
26 EXITCODE=$?
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
27 # Exitcode != 0 ?
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
28 if [ "$EXITCODE" -ne "0" ]; then
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
29 cat $TMPFILE >&2
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
30 fi
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
31 rm $TMPFILE
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
32
cc270db37d33 Directories re-arranged
Mikel Egana Aranguren <mikel-egana-aranguren@toolshed.g2.bx.psu.edu>
parents:
diff changeset
33 exit $EXITCODE