On Thu, 14 May 2009, Bart Schaefer wrote:
On Thu, May 14, 2009 at 3:49 AM, Atom Smasher <atom@xxxxxxxxxxx> wrote:
i'd like to pipe all stderr from a script into a command to do
logging...
but this isn't synchronous:
exec 2> >( multilog /path/ )
i need it to be synchronous so that multiple scripts running at the
same time (and also logging debug messages) can all log together and
not clobber each others output.
I'm not sure what you think "synchronous" implies here. Within a
particular "instance" of zsh, such as a single running script,
commands can be synchronous in the sense that zsh waits for the
command to finish before going on to the next one. However, multiple
scripts "running at the same time" already implies that the zsh
instances are asynchronous with respect to one another, so no command
started by a particular zsh instance will be synchronous with respect
to other instances (unless you employ some sort of external locking
scheme, but then you're just preventing the scripts from "running at
the same time").
==============
among different scripts (different invocations of the same script)
things are wildly asynchronous. but within each script, which is logging
debug output into multilog, i want to make sure that the stderr and
debug messages appear in the right order. this script shows how that
doesn't (always) happen:
#!/bin/zsh
exec 2> >(rot13)
date
dattxxx
date
dattxxx
date
dattxxx
date
dattxxx
the "dattxxx" commands are there to produce "command not found" errors
on stderr. with zsh 4.2.1 the redirect into a coproc makes it just hang.
That said ... have you tried your example above? I'd be mildly
surprised if multilog doesn't already do something to assure that
multiple loggers don't clobber one another's output. They might
intermingle their output, in which case you need to tag each line of
it with a PID or some such, but Dan Bernstein is generally pretty
compulsive about preventing data loss.
============
if there's one thing multilog does, it makes sure that multiple inputs
don't clobber each other. i am tagging each line with a PID so i can
grep out a particular process and see what's going on.
the problem i'm seeing with the script above, and variations on it, is
that sometimes the output is in the right order, but sometimes all of
stdout appears, followed by all of stderr.