473,883 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
+ 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 .AnonymousPipeC lientStream 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 AnonymousPipeCl ientStream 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 2620

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

Similar topics

3
3765
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 problem is the C++ lib does write stuffs on its stdout, and I would like to print those messages in a Tk frame. When I run the computation, it has it's own thread. So my question is : how van I redirect the dll's stdout to something I can
4
6313
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 for e.g. complex matrices. The problem: You can either print to a file (given by filename) or to stdout. To call the NAGC-method within an operator<< thus I have to redirect stdout to the given
3
2967
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 its output, but not (in this case) "nasm -v" , which displays version information. whats happening? slightly modified MS code: Dim myProcessStartInfo As New ProcessStartInfo("c:\nasm\nasm", "-v") myProcessStartInfo.UseShellExecute = False
0
1582
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() # Create re / write handlers
1
2599
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 file. My issue is that I try to read from the stdout stream and never get anything only if the program has exited. Is there a way of reading the redirected stdout from a DOS program in say real time? I have tried the async (BeginOutputReadLine) and...
10
7644
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
9759
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 each function call to the external library, I can insert the following: freopen("/dev/null", "w", stdout); However, after the function call I cannot figure out how to reroute stdout to the console. I tried early in the program defining: FILE...
0
1835
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 did not require redirection due to the fact that every X11 application can have an STDOUT associated with it. I then proceeded to take interest in making my code portable and looked at compiling it on windows, however Win32 GUI applications are...
1
1279
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 friend wrote a perl script that opens a pipe to my script, feeds it data, and then accepts the result. The problem here is that the python script's outputting the result to stdout via print statements isn't doing what we expected: my friend's perl...
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9779
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11114
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10835
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7960
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7114
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4205
muto222
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.