digitalmars.D.learn - Getting familiar with std.process
- jmh530 (34/34) Feb 09 2017 I haven't used std.process before and am trying to play around
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/8) Feb 09 2017 create_file must write to its stdout.
- jmh530 (4/13) Feb 09 2017 If only it were that easy. It's not my program writing to file,
I haven't used std.process before and am trying to play around with it. In the code below, the first file writes some text to an output file. My goal is to be able to read what is written to that file without creating the file itself. I'm not sure it's possible, but the second file is my attempt. The second file compiles the first (for the sake of simplicity), then creates a pipe with program it compiles, piping the result to stdout, then it saves the result to an output string, which I then print (or potentially manipulate in some other way in the future). But it doesn't print anything (why I'm posting here). I think the issue is that create_file doesn't write to stdout, it writes to file. Other than reading the file and then deleting it, I don't know what else to try. //create_file.d import std.stdio : toFile; void main() { toFile("test", "output.txt"); } //read_file.d //read_file.d import std.process; import std.stdio; void main() { auto command1 = execute(["dmd", "create_file.d"]); //auto command2 = execute(["create_file.exe"]); auto pipes = pipeProcess("create_file.exe", Redirect.stdout); scope(exit) wait(pipes.pid); foreach (line; pipes.stdout.byLine) writeln(line); }
Feb 09 2017
On 02/09/2017 12:44 PM, jmh530 wrote:I think the issue is that create_file doesn't write to stdout, it writes to file.Correct. Pipe works by piping the standard input/output streams.Other than reading the file and then deleting it, I don't know what else to try.create_file must write to its stdout. Ali
Feb 09 2017
On Thursday, 9 February 2017 at 21:36:46 UTC, Ali Çehreli wrote:On 02/09/2017 12:44 PM, jmh530 wrote:If only it were that easy. It's not my program writing to file, it's some one I didn't write. This was just sort of a beta test. I might need to look into the program a bit more.I think the issue is that create_file doesn't write tostdout, it writesto file.Correct. Pipe works by piping the standard input/output streams.Other than reading the file and then deleting it, I don't know what else to try.create_file must write to its stdout. Ali
Feb 09 2017