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

Jeffrey Malone ieatlint at tehinterweb.com
Sat Sep 27 13:30:01 PDT 2008


Definitely not part of any standard tool set I know.

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

What this will do, is execute the parinthesis first, and run stdout
through sed.  Then, it will push stderr onto stdout and pass it to the
logtest program.  This will work on bash and sh (and likely others).
There are of course other ways to do this, which may prove better in
your specific instances.  You could also use a non-printable character
instead of my example \t so that there's no output tat

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..

Jeffrey
On Sat, Sep 27, 2008 at 12:07 PM, Kristian Erik Hermansen
<kristian.hermansen at gmail.com> wrote:
> This one is a weird question.  I wonder if anyone here has the answer
> :-)  Regards...
>
>
> ---------- Forwarded message ----------
> From: Mark K. Mellis <mkmlists at mellis.com>
> Date: Sat, Sep 27, 2008 at 10:43 AM
> Subject: stderr and stdout, merged in a single file, in different colors
> To: uuasc at uuasc.org
>
>
> Hi, Group,
>
> Has anyone ever heard of a program that you can pipe stdout and stderr
> into and it will write a log file that has the two streams
> interleaved, but displayed in different colors?
>
> One of my java programmers is asking for this. She seems to think it
> is a normal part of the unix toolkit. I, of course, have never heard
> of such a thing. Sounds like it would be interesting.
>
> I saw a log viewer once that did something like it, but it sucked on a
> number of file descriptors and colored each one a different color
> using curses. It didn't capture the bits in a file, then play them
> back in color at will.
>
> ...Mark
>
> Mark K. Mellis
> Http://www.mellis.com/~mkm
> ------------------------------------------------------------------------
> --General instructions--  --Administrative requests--
> Post to this list,        Send to Majordomo at uuasc.org, no subject needed
> send to uuasc at uuasc.org  Include ONLY the following in the message BODY
> Last resort, send to       To unsubscribe: "unsubscribe uuasc"
> owner-uuasc at uuasc.org     Information or help: "info uuasc" or "help"
>
>
>
>
> --
> Kristian Erik Hermansen
> http://kristian-hermansen.blogspot.com
>
> _______________________________________________
> sf-lug mailing list
> sf-lug at linuxmafia.com
> http://linuxmafia.com/mailman/listinfo/sf-lug
>




More information about the sf-lug mailing list