www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Creating a "virtual" stdin/stdout/stderr

reply "Colin Grogan" <grogan.colin gmail.com> writes:
Hi all,

I want to create my own File in memory that I can pipe output to 
and read it in from another part of the program. I dont want to 
physically write data to disk, just store it in memory.

I've been trawling the documentation for the past while and the 
closest I can find is std.stdio.tmpfile(), however this always 
opens in "rb" and therefore isnt useful for me (I think!)

The reason I need to be able to make a File is because I want to 
send these IOstreams to std.processes spawnProcess().

Maybe I'm just looking in the wrong place?

Thanks in advance!
Oct 08 2013
parent reply "Colin Grogan" <grogan.colin gmail.com> writes:
On Tuesday, 8 October 2013 at 20:25:42 UTC, Colin Grogan wrote:
 Hi all,

 I want to create my own File in memory that I can pipe output 
 to and read it in from another part of the program. I dont want 
 to physically write data to disk, just store it in memory.

 I've been trawling the documentation for the past while and the 
 closest I can find is std.stdio.tmpfile(), however this always 
 opens in "rb" and therefore isnt useful for me (I think!)

 The reason I need to be able to make a File is because I want 
 to send these IOstreams to std.processes spawnProcess().

 Maybe I'm just looking in the wrong place?

 Thanks in advance!
I should have specified, this is std.stdio.File, not std.stream.File.
Oct 08 2013
parent reply "Daniel Davidson" <nospam spam.com> writes:
On Tuesday, 8 October 2013 at 20:26:49 UTC, Colin Grogan wrote:
 On Tuesday, 8 October 2013 at 20:25:42 UTC, Colin Grogan wrote:
 Hi all,

 I want to create my own File in memory that I can pipe output 
 to and read it in from another part of the program. I dont 
 want to physically write data to disk, just store it in memory.

 I've been trawling the documentation for the past while and 
 the closest I can find is std.stdio.tmpfile(), however this 
 always opens in "rb" and therefore isnt useful for me (I 
 think!)

 The reason I need to be able to make a File is because I want 
 to send these IOstreams to std.processes spawnProcess().

 Maybe I'm just looking in the wrong place?

 Thanks in advance!
I should have specified, this is std.stdio.File, not std.stream.File.
Is this helpful? import std.stdio; import std.process; void main() { auto p = pipe(); p.write("This is test\n"); p.close(); foreach( line; p.readEnd.byLine ) { writeln(line); } } Thanks Dan
Oct 08 2013
parent "Colin Grogan" <grogan.colin gmail.com> writes:
On Tuesday, 8 October 2013 at 20:38:56 UTC, Daniel Davidson wrote:
 On Tuesday, 8 October 2013 at 20:26:49 UTC, Colin Grogan wrote:
 On Tuesday, 8 October 2013 at 20:25:42 UTC, Colin Grogan wrote:
 Hi all,

 I want to create my own File in memory that I can pipe output 
 to and read it in from another part of the program. I dont 
 want to physically write data to disk, just store it in 
 memory.

 I've been trawling the documentation for the past while and 
 the closest I can find is std.stdio.tmpfile(), however this 
 always opens in "rb" and therefore isnt useful for me (I 
 think!)

 The reason I need to be able to make a File is because I want 
 to send these IOstreams to std.processes spawnProcess().

 Maybe I'm just looking in the wrong place?

 Thanks in advance!
I should have specified, this is std.stdio.File, not std.stream.File.
Is this helpful? import std.stdio; import std.process; void main() { auto p = pipe(); p.write("This is test\n"); p.close(); foreach( line; p.readEnd.byLine ) { writeln(line); } } Thanks Dan
It does! I see the Pipeing functionality in std.process now. Guess I should have looked harder :) Thanks.
Oct 08 2013