Re: A portable code question

From: nolan(at)celery(dot)tssi(dot)com
To: minshall(at)intellicon(dot)biz (Benjamin Minshall)
Subject: Re: A portable code question
Date: 2003-06-26 19:24:20
Message-ID: 20030626192510.4142.qmail@celery.tssi.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Assuming you're using file streams to write to the pipe, fflush() will do
> the trick.

The problem is that the pipe (from \o |tee xxxx) is intermingling writes
to stdout by tee with direct writes to stdout from within psql.

I do issue a fflush, because that's necessary to make the pipe do its
thing, but the next line of code also does a write to stdout and the pipe
generally doesn't have time to complete that write to stdout, resulting
in intermingled output. (fflush makes sure the pipe GETS the stream,
it doesn't wait around to make sure it's DONE with it, probably because
there's no way for whatever the pipe calls to report back when it is done.)

This is a bit of a hack, but adding an option to the \o code so that it
writes simultaneously to the pipe and to stdout instead of using tee
looks like a lot more work, especially since the code appears to have a
couple of other places where intermingling to stdout is possible,
especially if readline is used.

Throwing in "system('sleep 1');" was the way I resolved the timing
question here, but that may not be portable enough for inclusion into
the code base.
--
Mike Nolan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2003-06-26 20:05:30 Re: Two weeks to feature freeze
Previous Message Michael Meskes 2003-06-26 19:07:30 Re: ECPG thread success (kind of) on Linux