caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: "Nathaniel J. Gaylinn" <ngaylinn@cs.brown.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] OCaml IDE (OCaml and stdout/stderr)
Date: Mon, 20 Jun 2005 20:13:21 -0500 (CDT)	[thread overview]
Message-ID: <Pine.LNX.4.63.0506202007150.8755@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.58.0506201608110.2193@point>



On Mon, 20 Jun 2005, Nathaniel J. Gaylinn wrote:

>
> My program is having a hard time coping with how OCaml splits its output
> between stdout and stderr. The order in which a line of output is received
> from OCaml's stdout and a warning from its stderr seems to be completely
> random and therefore my program's output is also random. I'm pretty sure
> this has to do with how OCaml buffers stdout, but I'm not sure how to
> change this.

Welcome to programming on Unix.  The function you want is flush (in 
pervasives), with a signature  out_channel -> unit.  So to flush stdout, 
you just do flush stdout.  Same with stderr.  If the order of output is 
important, flush after every I/O.  Note that this a performance hit.

Note that this isn't an Ocaml problem- you can hit the same problem with 
C, C++, Java, Pascal, etc.

Note that being able to seperate out errors from everything else is nice 
when you're shell scripting.  This is why windows is iffy at best about 
really splitting the two different streams.

>> From your experience, do you think the buffering is taking place on
> OCaml's end or on Qt's?

Actually, I beleive it's the C stdio.h layer that doing the buffering. 
All the Ocaml flush function does is call the fflush function in C.

> Is there any nice way to force OCaml to flush its output buffers more
> often? Is there any way to customize what data OCaml sends to stdout and
> what it sends to stderr (this would be a nice feature to have!)? Do any
> other ideas come to mind?

output_string (and _int and _char and etc.) take an out_channel argument, 
allowing you to do:
    output_string stderr "Hello, world!\n"
to write something to stderr instead of stdout.

Brian


      parent reply	other threads:[~2005-06-21  1:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 20:08 Nathaniel J. Gaylinn
2005-06-21  0:34 ` [Caml-list] " Jacques Garrigue
2005-06-21 13:33   ` Nathaniel J. Gaylinn
2005-06-21 14:13     ` Nathaniel J. Gaylinn
2005-06-21  1:13 ` Brian Hurt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.63.0506202007150.8755@localhost.localdomain \
    --to=bhurt@spnz.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=ngaylinn@cs.brown.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).