How to get output of piped process?
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Sun Mar 7 15:05:15 UTC 2021
On Saturday, 6 March 2021 at 21:20:30 UTC, kdevel wrote:
>
> ```pipechain.d
> import std.stdio;
> import std.process;
> import std.conv;
> import std.array;
> import std.range;
> import std.algorithm;
>
> int main (string [] args)
> {
> auto p = pipe ();
> auto proc1 = spawnProcess (["cat"], stdin, p.writeEnd);
> auto q = pipe ();
> auto proc2 = spawnProcess (["cat"], p.readEnd, q.writeEnd);
> auto os = appender!string;
> q.readEnd.byChunk (4096).copy (os);
> auto res2 = wait (proc2);
> auto res1 = wait (proc1);
> stderr.writeln ("res1 = ", res1, ", res2 = ", res2);
> write (os[]);
> stderr.writeln ("fin");
> return 0;
> }
> ```
>
> AFAICS this is immune to SIGPIPE. Do I miss anything?
I probably missed that from the documentation and was trying to
make it work with pipeProcess.
More information about the Digitalmars-d-learn
mailing list