From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id C596FBBFB for ; Tue, 21 Jun 2005 03:13:24 +0200 (CEST) Received: from cenn.mc.mpls.visi.com (cenn.mc.mpls.visi.com [208.42.156.9]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j5L1DOOC029430 for ; Tue, 21 Jun 2005 03:13:24 +0200 Received: from [192.168.42.2] (bhurt.dsl.visi.com [208.42.141.66]) by cenn.mc.mpls.visi.com (Postfix) with ESMTP id 44E7D814B; Mon, 20 Jun 2005 20:13:21 -0500 (CDT) Date: Mon, 20 Jun 2005 20:13:21 -0500 (CDT) From: Brian Hurt X-X-Sender: bhurt@localhost.localdomain To: "Nathaniel J. Gaylinn" Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] OCaml IDE (OCaml and stdout/stderr) In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 42B769B4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocaml:01 ocaml:01 stdout:01 stderr:01 stdout:01 stderr:01 ocaml's:01 pervasives:01 buffering:01 ocaml's:01 stdio:01 buffering:01 fflush:01 char:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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