Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 08, 2016 Stdio.write/writeln and flushing | ||||
---|---|---|---|---|
| ||||
If i write something like: writeln("what to do?"); switch(readln[0 .. $ - 1]) { //.. } writeln("bye"); ...that works just as it should at Windows, started from a command prompt. However, if I run it from GNU Emacs, I have to manually flush the output after each time I do it before taking input, or else the output does not show when it should. I wonder if write(...) and writeln(...) should automatically flush, to enhance portability? Of course, I may be issing missing something? |
September 08, 2016 Re: Stdio.write/writeln and flushing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Somebody | On 08/09/2016 8:53 PM, Somebody wrote:
> If i write something like:
>
> writeln("what to do?");
> switch(readln[0 .. $ - 1])
> { //..
> }
> writeln("bye");
>
> ...that works just as it should at Windows, started from a command
> prompt. However, if I run it from GNU Emacs, I have to manually flush
> the output after each time I do it before taking input, or else the
> output does not show when it should.
>
> I wonder if write(...) and writeln(...) should automatically flush, to
> enhance portability? Of course, I may be issing missing something?
Same problem with Poderosa (terminal emulator which supports Cygwin) its at fault of the software which is client of the pipe. Phobos is doing what it should be doing.
|
September 08, 2016 Re: Stdio.write/writeln and flushing | ||||
---|---|---|---|---|
| ||||
Posted in reply to rikki cattermole | On Thursday, 8 September 2016 at 08:56:43 UTC, rikki cattermole wrote:
> Same problem with Poderosa (terminal emulator which supports Cygwin) its at fault of the software which is client of the pipe. Phobos is doing what it should be doing.
I think you're right... I think half of the command line applications wouldn't run anyway with such a shell regardless what Phobos does. Probably there is a way to configure Emacs otherwise, gotta search out...
|
September 08, 2016 Re: Stdio.write/writeln and flushing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Somebody | On 9/8/16 4:53 AM, Somebody wrote: > If i write something like: > > writeln("what to do?"); > switch(readln[0 .. $ - 1]) > { //.. > } > writeln("bye"); > > ....that works just as it should at Windows, started from a command > prompt. However, if I run it from GNU Emacs, I have to manually flush > the output after each time I do it before taking input, or else the > output does not show when it should. > > I wonder if write(...) and writeln(...) should automatically flush, to > enhance portability? Of course, I may be issing missing something? write and writeln depend on the behavior of FILE * for flushing, there is no specific flush. Note that FILE * examines the file descriptor and if it is detected as an interactive descriptor, flush is done every newline. If not, then flush is only done when the buffer is full. This is standard behavior forever, and is done to avoid performance problems when piping the result of a command to a file, for instance (flushing is expensive). Your emacs "console" is not marked by the OS as interactive (or however it's detected by FILE *, implementation defined), therefore flush does not happen on newlines. If you want to force newline flushing, use http://dlang.org/phobos/std_stdio.html#.File.setvbuf with a mode parameter of _IOLBF. -Steve |
September 09, 2016 Re: Stdio.write/writeln and flushing | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On Thursday, 8 September 2016 at 13:22:10 UTC, Steven Schveighoffer wrote:
>
> write and writeln depend on the behavior of FILE * for flushing, there is no specific flush.
>
> Note that FILE * examines the file descriptor and if it is detected as an interactive descriptor, flush is done every newline. If not, then flush is only done when the buffer is full. This is standard behavior forever, and is done to avoid performance problems when piping the result of a command to a file, for instance (flushing is expensive).
>
> Your emacs "console" is not marked by the OS as interactive (or however it's detected by FILE *, implementation defined), therefore flush does not happen on newlines.
>
> If you want to force newline flushing, use http://dlang.org/phobos/std_stdio.html#.File.setvbuf with a mode parameter of _IOLBF.
>
> -Steve
Ah, good to know an alternative way, I thought just about redefining write(...) and writeln(...) locally. Thanks.
I guess the real answer still is to configure OS/Emacs, as apparent when I did dub.init with Emacs.
|
Copyright © 1999-2021 by the D Language Foundation