473,385 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

Aug 29 '07 #1
2 1870
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
Aug 29 '07 #2
<mr****@gmail.comwrote:
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 - <sk***@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
Aug 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php...
2
by: Brian | last post by:
On a Slackware 9.1 box, I'm trying to detect if mpg123 is currently running/playing a song so that when the song is done, it'll play the next in the list. The problem is that popen'ing ps doesn't...
6
by: dwelch91 | last post by:
Greetings- This is on Linux... I have a daemon running as root and I want to execute another Python program as another user (a regular user). I have the name of the user and can use the 'pwd' and...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
2
by: Kyle0654 | last post by:
I've been searching for a solution to this problem for a while but haven't hit upon anything yet. Details: Using: MSVC++ .NET 2003 App type: Windows Forms Application (Managed C++)...
8
by: ToMasz | last post by:
There is a script running continuously which executes an external script in a loop using os.spawnlp(os.P_WAIT, 'extscript.py') function. After several hundred executions (cycles of the loop), the...
6
by: UJ | last post by:
I thought I saw somewhere that you could run a service from the cmd prompt and then any Console.Write you did would go to the screen. Is that true? TIA - Jeff.
2
by: Steve R. Hastings | last post by:
While studying iterators and generator expressions, I started wishing I had some tools for processing the values. I wanted to be able to chain together a set of functions, sort of like the...
2
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run....
8
by: grikdog | last post by:
How to I capture stdout output from a system call and pipe it back into my running script? system "echo foobar"; # how to continue here with "foobar" in stdin ?? ... I can fake it with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.