[sf-lug] Fwd: stderr and stdout, merged in a single file, in different colors

Asheesh Laroia asheesh at asheesh.org
Sun Sep 28 00:51:18 PDT 2008

On Sat, 27 Sep 2008, Jeffrey Malone wrote:

> Definitely not part of any standard tool set I know.

If you read to the bottom of my 
http://www.asheesh.org/note/software/stderred.html you'll see it's a 
fairly straight-forward trick in zsh. (-;

> It is possible, in a round-about way, to get what you want:
> You need to write a utility that does this, and it's not foolproof.
> For my example, let's say you have a program called "logtest" that
> takes 2 arguments.
> The first identifies a string that tells the program which lines are
> stdout (and all others are then stderr).  Let's say for this test all
> stdout lines will have a \t prepended.
> The second is say the logfile name to write to.
> Okay, and say "blah" is the program you want to log like this:
> (./blah | sed s:^:\\t: ) 2>&1 | logtest "\t" test.log

Oh, if you're doing that, you could have sed insert the colorizing control 

And if you're allowed to change the program doing the outputting, heck - 
that program could itself print the colorizing control codes! (-:

> Another, perhaps crazy idea, is a wrapper program.  It starts the
> child process with say popen, gets its pid, and then makes a fd for
> /proc/pid/fd/2.  A select loop could then work...
> You could also just use fifos and a tool with a select loop:
> mkfifo stderr
> mkfifo stdout
> ./blah >stdout 2>stderr
> And then with a select loop, open stderr and stdout and watch for incoming data.
> If there's a more eloquent way of doing this, I'd be quite interested
> to hear it..

Well I'd be happy to hear what you make of my LD_PRELOAD crazy idea. 
(Does that count as "standard unix power techniques"?)

-- Asheesh.

P.S. Context-switches are expensive.  Ask me about salsamixer sometime.

Always do right.  This will gratify some people and astonish the rest.
 		-- Mark Twain

More information about the sf-lug mailing list