473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

3 New Member
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 2540

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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.