Immediately tell which output was sent to stderr

Posted by Clinton Blackmore on Super User See other posts from Super User or by Clinton Blackmore
Published on 2009-08-24T16:16:59Z Indexed on 2010/04/07 22:43 UTC
Read the original article Hit count: 374

Filed under:
|
|

When automating a task, it is sensible to test it first manually. It would be helpful, though, if any data going to stderr was immediately recognizeable as such, and distinguishable from the data going to stdout, and to have all the output together so it is obvious what the sequence of events is.

One last touch that would be nice is if, at program exit, it printed its return code.

All of these things would aid in automating. Yes, I can echo the return code when a program finishes, and yes, I can redirect stdout and stderr; what I'd really like it some shell, script, or easy-to-use redirector that shows stdout in black, shows stderr interleaved with it in red, and prints the exit code at the end.

Is there such a beast? [If it matters, I'm using Bash 3.2 on Mac OS X].


Update: Sorry it has been months since I've looked at this. I've come up with a simple test script:

#!/usr/bin/env python
import sys

print "this is stdout"
print >> sys.stderr, "this is stderr"
print "this is stdout again"

In my testing (and probably due to the way things are buffered), rse and hilite display everything from stdout and then everything from stderr. The fifo method gets the order right but appears to colourize everything following the stderr line. ind complained about my stdin and stderr lines, and then put the output from stderr last.

Most of these solutions are workable, as it is not atypical for only the last output to go to stderr, but still, it'd be nice to have something that worked slightly better.

© Super User or respective owner

Related posts about color

Related posts about bash