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

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


On 08/24/2014 09:03 PM, simendsjo wrote:
> 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");
> }
> 

Never mind. I just found that I can set up a pipe
  auto f = pipe()
and then use f.readEnd


More information about the Digitalmars-d-learn mailing list