Hello all,
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.
thanks
WW
Peter Duniho - 29 Aug 2007 21:38 GMT
> I can do this in shell
>
[quoted text clipped - 9 lines]
> 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
Jon Skeet [C# MVP] - 29 Aug 2007 21:44 GMT
> I can do this in shell
>
[quoted text clipped - 9 lines]
> the input of second program but that will take some time on IO. I want
> do this quickly.
Have a look at PowerShell - it's all about that kind of thing.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too