Bug 10328 – std.stdio.write doesn't throw on failure
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2013-06-10T19:48:00Z
Last change time
2013-06-11T10:29:26Z
Assigned to
nobody
Creator
Jesse.K.Phillips+D
Comments
Comment #0 by Jesse.K.Phillips+D — 2013-06-10T19:48:24Z
Running a simple hello world program
import std.stdio;
void main() {
writeln("Hello World");
write("Hello World");
}
And executing where /dev/null is redirected as input to stdout (causing an invalid fd)
$ ./hello 1</dev/null
http://forum.dlang.org/post/[email protected]
Expected to see an exception thrown.
Comment #1 by lt.infiltrator — 2013-06-10T21:15:15Z
For comparison, here's the the same thing done to cat:
$ cat 1</dev/null
test
cat: write error: Bad file descriptor
Comment #2 by schveiguy — 2013-06-11T10:29:26Z
This is intended behavior. std.stdio.stdout is buffered, and the lines in your code have not attempted to write to the file descriptor yet.
If you add:
std.stdio.stdout.flush();
then it fails with an exception as expected. Note that C (and by using C's stdio as it's base, D also) decides whether to flush after newline depending on whether the file descriptor is a console or not.