Bug 6339 – stdin.byChunk throws with Windows pipes on command line
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-07-17T07:43:00Z
Last change time
2015-01-27T03:29:12Z
Assigned to
nobody
Creator
destructionator
Comments
Comment #0 by destructionator — 2011-07-17T07:43:35Z
testwin.d
===
import std.stdio;
void main() {
foreach(chunk; stdin.byChunk(4096))
assert(0, "never reached");
}
===
c:\Users\me\Desktop>echo "what" | testwin.exe
std.exception.ErrnoException@std\stdio.d(475): (Bad file descriptor)
It triggers the assert(0) if you just run testwin.exe and type some stuff into stdin normally, but piping output from another program into the program triggers that bad file descriptor exception.
I'm also looking into the byChunk hanging forever in some situations if the chunk size is bigger than the available file on Windows, but I haven't figured out how to reproduce that outside of IIS yet. I think the causes are likely related - IIS pipes data to stdin of my exe too.
Comment #1 by andy — 2015-01-27T02:28:13Z
I've test this on dmd 2.066.1 on both windows and linux and they both fire the exception:
$ echo what | ./test
[email protected](6): never reached
----------------
./test(_Dmain+0x4f) [0x806bb9f]
etc...
D:\projects\d>echo what | test
[email protected](6): never reached
----------------
0x00402AFD
etc...
At some point during the last 4 years this must have been fixed, but I don't really wanna search for the commit.
Comment #2 by schveiguy — 2015-01-27T03:29:12Z
There was an issue in the DMC runtime where it did not handle a closed pipe when doing a read, instead it treated it as a bad FD. I actually patched DMC to fix this (unrelated to this, it was for std.process), so that's probably when this was fixed too.