Tango I/O bug?

kris foo at bar.com
Mon Sep 17 20:04:35 PDT 2007


Frits van Bommel wrote:
> Jason House wrote:
>> Sean Kelly Wrote:
>>
>>> Jason House wrote:
>>>> outStream.formatln("= {}\n", valueToReturn); // adds extra \n and 
>>>> flushes
>>> Seems okay, though it's difficult to say from just that line.  Is 
>>> output redirected?  Are objects being re-used?  Is .close() perhaps 
>>> not being called if output is to a file?
>>
>>
>> Output is going to Cout.stream and is never closed.  The code relies 
>> on formatln to flush the output.  It does real time communication in 
>> plain text with a 3rd party controlling application.  This line really 
>> was from the program.  In this particular example, valueToReturn is of 
>> type char[] and is literally "HouseBot"
> 
> This part is likely your problem: "It does real time communication in 
> plain text with a 3rd party controlling application"
> That probably means the output is redirected and not sent to an actual 
> console, right?
> The default behavior for Stdout is to auto-flush only if the output is 
> sent to an actual console (i.e. isn't redirected).
> 
> To make sure flushing occurs, execute "Stdout.flush = true;" somewhere 
> at the start of your program (main(), a static this(), or just right 
> before the first output).


Yeah, Stdout and Cout inhibit *automatic* flush when the console is 
redirected. If you think about it, the whole automatic flush thing is a 
'shortcut' so that output to the real console doesn't need an explicit 
call to flush() each time. It's a royal PITA to support that :)

Anyway, the most effective route here is simply to invoke flush() 
explicitly, whenever you actually need to. For example:

# outStream.format("blah blah").flush;





More information about the Digitalmars-d-learn mailing list