I have some problems to understand the difference of using the STDOUT and using "anonymous pipes" as shown below:
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
Code:
using System;
using System.Diagnostics;
using System.IO;
namespace ProcessTest
{
class Program
{
static void Main(string[] args)
{
// configure ProcessStartInfo to start some exe and to redirect the STDOUT
ProcessStartInfo processStartInfo = new ProcessStartInfo(@"C:\WINDOWS\system32\ping.exe");
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
// start the process
Process process = new Process();
process.StartInfo = processStartInfo;
process.Start();
// read from the redirected STDOUT
StreamReader myStreamReader = process.StandardOutput;
Console.WriteLine(myStreamReader.ReadToEnd());
// close process & wait for user input
process.Close();
Console.ReadKey();
}
}
}
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