Created attachment 418
Patch for stdio.d version 2.031
FILE*s opened with popen should be closed with pclose, not fclose. I've attached a patch (against stdio.d, version 2.031) which makes File.close do this automatically.
This bug causes problems with e.g. the std.process.shell function, which throws an exception whenever a program returns with a nonzero exit status. Example:
import std.process;
void main() { shell("dmd"); }
When DMD is run with no arguments it returns 1, so running the program above causes the following error:
std.contracts.ErrnoException: std/stdio.d(397):
Could not close file `dmd' (Success)
I've created a simple patch against stdio.d to fix this. (It's my first patch ever, so be gentle...) It adds the member "bool isPipe" to the File.Impl struct, which simply tells whether the file is opened with popen or not. The File.close() method checks isPipe and calls pclose if it is true. Note that pclose returns the exit status of the program, so I had to remove the errnoEnforce for that case.
Another solution is of course to add a method File.pclose, and require that all popen'ed Files must also be pclosed. However, I think it is better if File.close does this automatically.
Comment #1 by bugzilla — 2010-04-26T00:14:41Z
*** Issue 4127 has been marked as a duplicate of this issue. ***
Comment #2 by braddr — 2010-09-08T02:07:01Z
Created attachment 750
updated and slightly alternate implmentation
This patch makes me a little ill.. abusing an exception to propagate more data because the File abstraction around the pipe is a poor fit.
BUT, I really want to be able to get both the string output as well as it's result code. So.. thoughts?