The current Posix implementation of spawnProcess calls close on
every fd from 3 to the max fd count (as gathered by rlimit()).
Given that the process doesn't have that many descriptors open
in the *vast* majority of cases, this is quite pessimal.
Instead, use poll() to see which descriptors are actually open,
and close those.
Current document says:
```d
auto p = pipe();
p.writeEnd.writeln("Hello World");
assert (p.readEnd.readln().chomp() == "Hello World");
```
This means that buffer is yet to be flushed.
Therefore `p.readEnd.readln` can't recieve the input, for readln waits forever if the buffer is not flushed.
Then I fixed as follow:
```d
auto p = pipe();
p.writeEnd.writeln("Hello World");
p.writeEnd.flush();
assert (p.readEnd.readln().chomp() == "Hello World");
```
This diff: This diff makes it possible to specify your preferred shell for the various `*shell` functions in `std.process`. By default it uses the new `nativeShell` function. `nativeShell` to always returns the native system shell (see the "some history" section for why this is the default value). I chose to create `nativeShell` rather than changeing `userShell` because I think it is still valuable to have something like `userShell` around in Phobos.
The one part of this diff I'm not super thrilled by is the use of variadic arguments (easier to see than to explain); if you have a suggestion for something better I'd love to hear it :).
Note: The default shell is a breaking change for Windows, which probably *should have* been broken same as posix in the diffs listed in the history section below, but I suspect was overlooked. Find rationale behind making a breaking change at all here: https://issues.dlang.org/show_bug.cgi?id=15000.
Some history:
a524a3571b
and
f537cb50b5
Tried to move us from a world where we preferred the shell specified in the SHELL environment variable to a world where we always went with the native system shell, /bin/sh for posix. The former of those revisions was reverted in:
5b2b1fb594
Because the documentation was not updated to reflect the change.
Presently: we are in a state of schism, whereby `userShell` has behavior that does not align with what is actually used in `executeShell`, `pipeShell`, and `spawnShell`. This is something we *must* resolve.
Personal pain: This bit me when one of my scripts at work stopped working because it dependend on features that don't exist in `sh` (but do in `bash`, `zsh`, etc). It was really frustrating that there was no simple way to work around this and specify my preferred shell; it is, of course, possible to leverage the various `escape*` functions from `std.process` and `spawnProcess` to use whichever shell I prefer, but this seems like something warranting first class support. I was sad to not have something like this after a breaking change.
Currently using both alloca and finalizers (==destructor call) in a function is unsupported excepting Win32 (issue 3753). However compiler doesn't recognize implicit destructor calls sometimes, and they're not called during stack unwinding (issue 14708).
For the workaround, replace alloca call with malloc + scope(exit) free.