473,385 Members | 1,282 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.

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 2530

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

Similar topics

3
by: David Douard | last post by:
Hi everybody, let me explain by problem: I am working on an application which consists in a C++ dll (numeric computations) and a Python IHM (Python/Tk), which must run under Linux and win32. My...
4
by: Alexander Stippler | last post by:
Hi, The short story: I have to redirect stdout (not cout!!) to an ostream. How can I manage this? The long story: I use the NAGC numerics library with C++ and want to use its output routines...
3
by: Patrick Porter | last post by:
Im trying to capture the stdout from running a process from within my app. I've been dinking around using the code straight off the MS site. i can get "ipconfig / all" (for example) to send back...
0
by: Elad | last post by:
Hello All, I am trying to capture some printf's from a C function called by python. <Working under winxp> I have tried to following: STDOUT = 1 # stdout fd (re, we) = os.pipe() #...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
10
by: SamG | last post by:
How could i make, from inside the program, to have the stdout and stderr to be printed both to a file as well the terminal(as usual).
4
by: ElderGeek | last post by:
Hi, all. I am coding in C on Linux, and using an external library provided by others. This library generates a batch of error/warning messages to stdout, which I do not want to see. Before...
0
by: Tom Gaudasinski | last post by:
Greetings, I'm trying to redirect python's stdout to another location. The reason for this is that I'm embedding python in an application. Now, originally my code was developed for Linux and that...
1
by: =?ISO-8859-1?Q?Richard_Sim=F5es?= | last post by:
Hopefully, this explanation will sufficiently clear despite the lack of code. I wrote a python script that takes data via stdin, does stuff with the data, and outputs the result to stdout. A...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.