www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2186] New: Out of order in stdout

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2186

           Summary: Out of order in stdout
           Product: D
           Version: 1.024
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: mihail.zenkov gmail.com


Simple test case:

import std.stdio;
import std.process;

void main() {
        writefln("line1");
        system("echo line2");
        writefln("line3");
        system("echo line4");
}



line1
line2
line3
line4

All fine. But when i try redirect it to file or other process, i have:

line2
line4
line1
line3

gdc (GCC) 4.1.2 20070214 ( gdc 0.24, using dmd 1.024)


-- 
Jun 30 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2186


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





"It's not a bug, it's a feature". It's simple, really. The pipe transforms
stdio for the D program from line-buffered to block-buffered. The writefln call
does not flush the stream, and that's about what happens. The same happens in a
C program using printf and system.

To fix, you may want to insert calls to fflush(stdout) after the writes.


-- 
Jun 30 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2186







 "It's not a bug, it's a feature". It's simple, really. The pipe transforms
 stdio for the D program from line-buffered to block-buffered. The writefln call
^^^^^ I meant stdout not stdio. --
Jun 30 2008