D: How do I pipe (|) through three programs using std.process?

BoQsc vaidas.boqsc at gmail.com
Sun Nov 12 19:59:41 UTC 2023


To make this thread more complete, here is the final version.

```
import std.stdio;
import std.process;

version (Windows) { enum Find = "find"; }
version (Posix) { enum Find = "grep"; }


int main (string [] args)
{
    auto p1 = pipe;
    auto p2 = pipe;

    auto pid1 = spawnShell("echo HelloWorld", stdin, p1.writeEnd);
    auto pid2 = spawnShell(Find ~ " \"HelloWorld\"", p1.readEnd, 
p2.writeEnd);
    auto pid3 = spawnShell(Find ~ " \"HelloWorld\"", p2.readEnd, 
stdout);

    wait (pid1);
    wait (pid2);
    wait (pid3);
    return 0;
}
```

It is equal to:
* Windows: `echo HelloWorld | find "HelloWorld | find 
"HelloWorld"`
* Linux: `echo HelloWorld | grep "HelloWorld | grep "HelloWorld"`


More information about the Digitalmars-d-learn mailing list