mr****@gmail.com wrote:
I can do this in shell
dir /a/b/s | grep something
This is piping the output of first program dir to input of second
program grep .
I would like to implement this in C#. Is there a way to implement pipe
in c# programming?
I can save the output of first program to disk and read from disk as
the input of second program but that will take some time on IO. I want
do this quickly.
You can use the System.Diagnostics.Process class, redirecting standard
output of one process and feeding that to the redirected standard input
of another. In this case, you'd have two Process instances, one for
"dir" and one for "grep".
Note that "dir" isn't a program; it's a built-in command for cmd.exe.
So you'll need to specify "cmd.exe" as the actual executable for the
"dir" process, with the appropriate switches to execute the "dir" command.
Another note: I don't have first-hand experience using a program like
"grep" in this way, where the program reads to the end of the stream.
I'm pretty sure you just close the redirected input stream, but you
might have to experiment a bit to find out the exact technique, if that
assumption isn't correct.
Pete