How do I compose pipes?
Anthony
anthoq88 at gmail.com
Thu Jan 28 10:16:39 UTC 2021
This post https://dlang.org/library/std/process/pipe.html
mentions:
>Pipes can, for example, be used for interprocess communication
>by spawning a new process and passing one end of the pipe to the
>child, while the parent uses the other end. (See also
>pipeProcess and pipeShell for an easier way of doing this.)
```
auto p = pipe();
auto outFile = File("D downloads.txt", "w");
auto cpid = spawnProcess(["curl",
"http://dlang.org/download.html"],
stdin, p.writeEnd);
scope(exit) wait(cpid);
auto gpid = spawnProcess(["grep", "-o", `http://\S*\.zip`],
p.readEnd, outFile);
scope(exit) wait(gpid);
```
How am I able to compose the pipes from pipeProcess if I can't
pass in an existing pipe into the function. Eg.
```
auto p = pipeProcess("ls");
auto q = pipeProcess("cat", stdin = p.stdout); //it would be good
to do this or something like it
```
Do I need to manually extract the output from pipes.stdin.readln
and place it in pipes.stdout.writeln?
Or is there an easier way to do this?
Thanks
More information about the Digitalmars-d-learn
mailing list