D: How do I pipe (|) through three programs using std.process?
BoQsc
vaidas.boqsc at gmail.com
Sun Nov 12 10:57:12 UTC 2023
On Windows:
While trying to use `spawnshell` I discovered that I can not use
any alphabetical letters inside the `spawnProcess([Find,
"Hello"])` it all works when they are numerical `[Find, "6515"]`.
As of recent testing `[Find, "df123"]` also is acceptable,
but not when letter is on the right `[Find, "df123d"]`
Unable to figure why this is the case and how to resolve it.
**Working example without problems:**
```
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 123", stdin, p1.writeEnd);
auto pid2 = spawnProcess([Find, "123"], p1.readEnd,
p2.writeEnd);
auto pid3 = spawnProcess([Find, "123"], p2.readEnd, stdout);
wait (pid1);
wait (pid2);
wait (pid3);
return 0;
}
```
**Output:**
```
123
```
**Immediate issue if alphabetical letters are used:**
```
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 = spawnProcess([Find, "HelloWorld"], p1.readEnd,
p2.writeEnd);
auto pid3 = spawnProcess([Find, "HelloWorld"], p2.readEnd,
stdout);
wait (pid1);
wait (pid2);
wait (pid3);
return 0;
}
```
**Output:**
```
FIND: Parameter format not correct
FIND: Parameter format not correct
The process tried to write to a nonexistent pipe.
```
More information about the Digitalmars-d-learn
mailing list