Pipe one shell command into another
Griffon26 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jan 30 07:57:49 PST 2016
On Saturday, 30 January 2016 at 15:12:26 UTC, Andrew wrote:
> foreach(line; pipesLs.stdout.byLine)
> pipesSort.stdin.writeln(line);
Because you write sort's input first and read its output later,
it might end up blocking if ls generates too much data. The
output pipe of sort will fill up, causing sort to block and not
read data from its input pipe anymore, resulting in your program
blocking when the input pipe has filled up.
I have a piece of code using poll to write to two input pipes and
read from one output pipe, but it's a bit more complex than what
you need. However, it also uses pipeShell to specify multiple
commands at once. Since your program only needs to read the
output (and not generate input), you may find pipeShell useful.
https://github.com/Griffon26/tdiff3/blob/87709dd51c279e9896f37ba1cef477a525e44562/source/gnudiff.d
Disclaimer: I'm not an experienced D programmer. My D code may
not be pretty =)
More information about the Digitalmars-d-learn
mailing list