www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10328] New: std.stdio.write doesn't throw on failure

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

           Summary: std.stdio.write doesn't throw on failure
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: Jesse.K.Phillips+D gmail.com



19:48:24 PDT ---
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/egmumvacbiflshtjofay forum.dlang.org

Expected to see an exception thrown.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 10 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10328


Infiltrator <lt.infiltrator gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lt.infiltrator gmail.com



PDT ---
For comparison, here's the the same thing done to cat:

$ cat 1</dev/null
test
cat: write error: Bad file descriptor

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 10 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10328


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy yahoo.com
         Resolution|                            |INVALID



10:29:26 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 11 2013