[Issue 20215] New: redirected console app looks hang w/o .flush
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 16 07:50:46 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20215
Issue ID: 20215
Summary: redirected console app looks hang w/o .flush
Product: D
Version: D2
Hardware: x86_64
OS: Windows
Status: NEW
Severity: minor
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: black80 at bk.ru
-----------------------
import std;
void main() {
for (int k=1; k<10_000; ++k)
// non ascii doesn't matter, just for longer string
writeln( "hello world and привет and salut");
"done.".writeln;
// without it - SUBJ
//stdout.flush;
// without it (this app finished here) OK
readln;
}
-----------------------
NB:
REDIRECTED output to file
prog.exe > file.data
output at the end looks like this:
hello world and привет and salut
hello world and привет and salut
hello world and привет and salut
hello world and
I don't see that app is finished - no line "done."
app looks halted at some middle point.
lab:
one console runs app.
other console (FAR manager = like Night Commander) view/F3 at file.data
why so strange?
cause prints to real console is 100x slower then to file.
and viewing file/log u can stop at any interested line while output is
continue.
so look at such output my thoughts is:
- maybe something wrong was compiled?
- maybe GC freeze for minutes? what?!
- maybe try same with C#?.. hmm.. is working here!.. what again wrong with D?
- maybe to use printf instead writeln?
possible solution (iirc Stroustrup said it at 2nd edition C++ book in 90s for
cin/cout)
when u try read data from input, flush output first.
when program prints "input numbers: " and try read nums but string is buffered
and no hints (on screen) what should user think?
so
readln should flush output first
or better is
// automatically flush but can be manually disabled for -1 syscall
readln( term ='...', shouldFlush =true)
// shouldFlush=false - means same. u will forget to flush
current workaround - manually flush
better solution - flush automatically for stupid and forgetful users like me
--
More information about the Digitalmars-d-bugs
mailing list