Search code examples
c#.netstreamsystem.diagnostics

What's a Standard Output Stream?


I have code that looks more or less like the code below but it doesn't retrieve text from the application I'm opening (notepad). Maybe I'm missing the point. Can someone explain what a Standard Output Stream is and whether in fact it's what I want to use if I want to open an application and then retrieve the text it displays?

ProcessStartInfo psi = new ProcessStartInfo("notepad.exe", "c:\\test.txt");
psi.RedirectStandardOutput = true;
psi.UseShellExecute = false;

Process p = new Process();
p.StartInfo = psi;
p.Start();

string s = p.StandardOutput.ReadToEnd();

Solution

  • There are three standard streams input output and error. They are mostly used by console programs to send in put and out put to each other. notepad is a gui program and notion of standard out and standard in don't really map. A example of usage would be dir | fndstr hi in this case the command dir sends its out put to the standard input of fndstr.