File.tmpfile() cannot be used as a pipe?

simendsjo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 24 12:03:54 PDT 2014


I don't know the arguments for my process before reading some of stdin.
I was thinking I could solve this by creating a temporary file as a
"stdin buffer" while I found out the correct argument and could launch
the process. Unfortunately, this fails.

Error: 'object.Exception at std/stdio.d(2070): Enforcement failed'.

The enforcment that fails:
    enforce(f._p && f._p.handle);
in LockingTextWriters ctor where f is the passed in File.

Test code:

import std.stdio, std.process;
void main() {
    auto f = File.tmpfile();
    f.write("works");
    auto pid = spawnProcess(["echo"], f);
    f.write("fails");
}


More information about the Digitalmars-d-learn mailing list