running pipe in c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mrwwli@gmail.com

    #1

    running pipe in c#

    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

    #2
    Re: running pipe in c#

    mrwwli@gmail.co m 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.Diagnost ics.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

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: running pipe in c#

      <mrwwli@gmail.c omwrote:
      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.
      Have a look at PowerShell - it's all about that kind of thing.

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

      Comment

      Working...