www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - File.tmpfile() cannot be used as a pipe?

reply simendsjo <simendsjo+dlang gmail.com> writes:
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 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");
}
Aug 24 2014
parent simendsjo <simendsjo+dlang gmail.com> writes:
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 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
Aug 24 2014