Opening temporary files for std.process.spawnProcess input/output
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 26 07:51:51 PST 2015
On 2/25/15 2:09 PM, Ali Çehreli wrote:
> It looks like the file is closed when spawnProcess is finished. I don't
> know whether it is done by spawnProcess explicitly or whether it is a
> behavior for temporary files.
I know the problem is solved, but I wanted to chime in with some
explanation here:
Yes, it's closed on purpose. Typically, when you open a file descriptor
in order to have the child use it for stdin/stdout/stderr, you want to
close the handle on the parent, since the parent isn't using it.
Even with pipes, there are 2 ends. The child uses one and closes the
other, and the parent uses one and closes the other.
There is a way to disable this behavior, use Config.retainStdout.
http://dlang.org/library/std/process/config.html
The only time these aren't closed by default is if the default handles
are used (you don't want to close e.g. stdout in the parent if you use
it in the child).
-Steve
More information about the Digitalmars-d-learn
mailing list