[HACKERS] A portable code question

2003-06-26 Thread nolan
In the little fix I came up with for psql last night, I need to be able
to ensure that something sent to a pipe (and then to stdout) completes 
before issuing the prompt directly to stdout.  

I did this with: system ('sleep 1');, but I'm fairly sure that is 
not portable nor does it ENSURE completion. 

What's the proper way to do this?  And what's a good book on writing
portable code?
--
Mike Nolan

---(end of broadcast)---
TIP 8: explain analyze is your friend


Re: [HACKERS] A portable code question

2003-06-26 Thread Benjamin Minshall
Assuming you're using file streams to write to the pipe, fflush() will do
the trick.

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf Of
 [EMAIL PROTECTED]
 Sent: Thursday, June 26, 2003 2:20 PM
 To: pgsql hackers list
 Subject: [HACKERS] A portable code question


 In the little fix I came up with for psql last night, I need to be able
 to ensure that something sent to a pipe (and then to stdout) completes
 before issuing the prompt directly to stdout.

 I did this with: system ('sleep 1');, but I'm fairly sure that is
 not portable nor does it ENSURE completion.

 What's the proper way to do this?  And what's a good book on writing
 portable code?
 --
 Mike Nolan

 ---(end of broadcast)---
 TIP 8: explain analyze is your friend



---(end of broadcast)---
TIP 7: don't forget to increase your free space map settings


Re: [HACKERS] A portable code question

2003-06-26 Thread Andrew Dunstan

Or if you want this behaviour all the time, one call of
  setvbuf(mypipe,(char *)0,_IONBF,0);
should do the trick (much easier than remebering to have to call fflush()
all the time).

If not using streams, and just calling write(), then you probably don't have
to worry.

andrew

BTW, system('sleep 1'); probably won't compile, and 'system(sleep 1);'
is bad news. Try man 3 sleep for more info.

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

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] Behalf Of
 [EMAIL PROTECTED]
 Sent: Thursday, June 26, 2003 2:20 PM
 To: pgsql hackers list
 Subject: [HACKERS] A portable code question


 In the little fix I came up with for psql last night, I need to be
 able to ensure that something sent to a pipe (and then to stdout)
 completes before issuing the prompt directly to stdout.

 I did this with: system ('sleep 1');, but I'm fairly sure that is
 not portable nor does it ENSURE completion.

 What's the proper way to do this?  And what's a good book on writing
 portable code?
 --
 Mike Nolan

 ---(end of
 broadcast)--- TIP 8: explain analyze is your
 friend



 ---(end of
 broadcast)--- TIP 7: don't forget to increase
 your free space map settings




---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly


Re: [HACKERS] A portable code question

2003-06-26 Thread nolan
 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 ) 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


---(end of broadcast)---
TIP 8: explain analyze is your friend