English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] flushing stdout with flush stdout not good?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-09-03 (20:02)
From: Markus Mottl <markus@m...>
Subject: Re: [Caml-list] flushing stdout with flush stdout not good?
On Mon, 03 Sep 2001, Michael Leary wrote:
> I'm programming a realtime bot (as you may know :) and using printf
> with a newline terminated format string followed by a call of fse (
> short for "flush stdout" in my prog) really doesn't work very well at
> flushing stdout -- commands don't get read properly by the system,
> and get processed in chunks, rather than as sent.  For some reason
> calling print_newline is amazingly more effective, i.e. leaving the
> newline out of the printf format string, and letting print_newline ()
> take care of it.

I guess you are using the Format-module, not the Printf-module. The
latter works directly on the stdout buffer, whereas the first maintains a
"pretty-printing buffer" where it can break lines as required.

You can use "print_flush" or "@?" within the format string to flush
things. But be careful: the latter closes all open pretty-printing boxes
as is logically necessary for this operation so better do this only when
all boxes are closed anyway (or you are sure that you want to have them
all closed).

If you don't need automatic line-breaking functionality, the
"Printf"-module is just fine.

Markus Mottl

Markus Mottl                                             markus@oefai.at
Austrian Research Institute
for Artificial Intelligence                  http://www.oefai.at/~markus
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr