468,727 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,727 developers. It's quick & easy.

C#-APP: redirecting STDOUT vs. anonymous pipes: what's the difference?

I have some problems to understand the difference of using the STDOUT and using "anonymous pipes" as shown below:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4.  
  5. namespace ProcessTest
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             // configure ProcessStartInfo to start some exe and to redirect the STDOUT
  12.             ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\WINDOWS\system32\ping.exe");
  13.             processStartInfo.UseShellExecute = false;
  14.             processStartInfo.RedirectStandardOutput = true;
  15.  
  16.             // start the process
  17.             Process process = new Process();
  18.             process.StartInfo = processStartInfo;
  19.             process.Start();
  20.  
  21.             // read from the redirected STDOUT
  22.             StreamReader myStreamReader = process.StandardOutput;
  23.             Console.WriteLine(myStreamReader.ReadToEnd());
  24.  
  25.             // close process & wait for user input
  26.             process.Close();
  27.             Console.ReadKey();
  28.         }
  29.     }
  30. }
  31.  
As you can see the program starts some executable in a Process object (lines 11-19). The STDOUT of this Process object is redirected (line 13, 14) and printed directly to the console (line 23).


Questions
1. Is this a so called "standard I/O channel" (the STDOUT) what I am using here to get my output?

2. If question 1 is true, is this so called "standard I/O channel" (the STDOUT) also a kind of "anonymous pipe"? As far as I understood an "anonymous pipe" is just a pipe without a name and used for communication between a parent and child process. I think this is the case between this program (Main() = parent) and the Process object (= child).

3. In this special case: What would be the benefit in using the System.IO.Pipes.AnonymousPipeClientStream class (available since .NET 3.5) in this progam? The motivation behind this is that I have a more complex program, which works pretty the same way as shown above. Additionally I write some input via the STDIN to the Process object and read the STDOUT and STDERR asychronously to get rid of the race condition problem.
I am not sure if (a) using the "standard I/O channels" (like shown above) or (b) using the AnonymousPipeClientStream class is the most reliable and direct way to do make simple i/O with a Process object.


Thanks a lot for your help,
K
Feb 25 '08 #1
0 2125

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by David Douard | last post: by
4 posts views Thread by Alexander Stippler | last post: by
3 posts views Thread by Patrick Porter | last post: by
reply views Thread by Tom Gaudasinski | last post: by
1 post views Thread by =?ISO-8859-1?Q?Richard_Sim=F5es?= | last post: by
xarzu
1 post views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.