Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

running pipe in c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mrwwli@gmail.com - 29 Aug 2007 21:16 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.