News for hackers. Stuff that matters.
Re:Make your STDERR red by anon_d on Tuesday December 13, 2011 @05:38PM (#3349689)
How the hell is this even remotely clean?
Re:Make your STDERR red by joh6nn on Tuesday December 13, 2011 @05:50PM (#3349734)
"cleanest way i've seen" != "ideal"

it isn't a horrible mangling of pipes and/or file descriptors, or some custom wrapper script that you have to run before every command, or any of the other frightening ways to do this that i've seen. it's a simple library that you can load or unload easily, that works system wide, without being an impenetrable, unmaintainable mess. as far as these things go, that's clean.

Re:Make your STDERR red by burgerbrain on Tuesday December 13, 2011 @05:48PM (#3349728)
Yeah, this is a tad hackish for my tastes honestly, makes to many assumptions.

The way I came up with while brainstorming a while ago (never got around to fully implementing it) is to create a PTY wrapper that you can fire off a program with.

Basically it creates a new PTY and wires it up to it's own controlling PTY, and forks of a child under the new one. You can then trivially do a lot of things transparently, like separating stdout and stderr (normally both stdout and stderr would be attached to the slave side of the PTY (/dev/tty), but if you attach them to a different fd then the select on the master/parent side can do things like color them).

EDIT: if it helps you picture it, this is basically doing userland STREAMS ;)

I'd estimate you could do this for around 250 lines of C. Maybe I'll see what I can do after dinner.

Re:Make your STDERR red by burgerbrain on Tuesday December 13, 2011 @08:16PM (#3350160)
Ok, banged this together: https://gist.github.com/1474748

Based off jgreco's 'vindication': https://github.com/jgreco/vindication

Usage:

  `./redwrapper python -c 'import os; print "Yo!"; os.write(2, "Jola\n\r");'`
  `./redwrapper zsh`
(zsh works with it, but bash doesn't currently for some stupid reason. something about what it expecting stderr to be /dev/tty or something I believe).

This is rough code, if you want to use regularly/seriously I suggest reviewing the code. I didn't pay attention much to standards compliance, I've only tested on Linux right now. I know that PTY stuff can get hairy on different *nix's, so beware of that.

EDIT: whoops, remove that '-g -lefence' from the Makefile too before you use this.

Re:Make your STDERR red by roel_v on Wednesday December 14, 2011 @08:04AM (#3351648)
You'd have to modify every script you ever run on a machine, and modify every command you ever type in, to make this work. Any serious solution to this problem needs to be 100% transparent to the user - i.e., wrapper programs are not an option.
Re:Make your STDERR red by burgerbrain on Wednesday December 14, 2011 @12:17PM (#3352618)
No, you can just run your shell under it. You certainly wouldn't want to actually modify anything.

The following sequence works:

  `./redwrapper zsh
  `python -c 'import os; print "Yo!"; os.write(2, "Jola\n\r");'`
This is because the values of stderr/stdout are inherited, unless they are purposely overwritten (redirection or anything that allocates it's own PTY (like 'ssh'), both of which of course disables 'red-ification').

Anyway, neither of these solutions are something I would ever deploy in an "always on" setup (although it could be done in mine as well). You certainly wouldn't want to do it for your users, so they're always going to have to type something (or mess their shell's init files, which should work for mine as well).

So this is about as transparent to the user as I dare make it. Unfortunately it is not 100% transparent to the programs you are running under it since they can figure out that stderr is not /dev/tty. Nothing seems to care, with the exception of bash, which uses stderr for seemingly everything inexplicably.

Re:Make your STDERR red by joeyh on Wednesday December 14, 2011 @10:50AM (#3352251)
Or you can just modify screen(1)
Re:Make your STDERR red by bdonlan on Tuesday December 13, 2011 @09:54PM (#3350366)
If you split stdout and stderr, you can end up with the order of output changing - your output process might not get around to reading its input ends until it has data at both, and then it can't tell which is which.
Re:Make your STDERR red by burgerbrain on Tuesday December 13, 2011 @10:41PM (#3350470)
"If you split stdout and stderr, you can end up with the order of output changing"

That is true. I find it doesn't matter terribly much in practice though. Obviously with some programs it might.

"your output process might not get around to reading its input ends until it has data at both, and then it can't tell which is which."

I'm not quite sure what you mean.