Comment #0 by mihail.zenkov — 2008-06-30T18:08:05Z
Simple test case:
import std.stdio;
import std.process;
void main() {
writefln("line1");
system("echo line2");
writefln("line3");
system("echo line4");
}
# gdc test.d -o test
# ./test
line1
line2
line3
line4
All fine. But when i try redirect it to file or other process, i have:
# ./test | cat
line2
line4
line1
line3
gdc (GCC) 4.1.2 20070214 ( gdc 0.24, using dmd 1.024)
Comment #1 by andrei — 2008-06-30T21:29:29Z
"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.
Comment #2 by andrei — 2008-06-30T21:30:19Z
(In reply to comment #1)
> "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.