0

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();
John Smith
  • 4,416
  • 7
  • 41
  • 56
  • 6
    StandardOutput is what is is written to the console. The various output streams are for command-line style programs. You will not be able to capture Notepad output via this method. – Joe Jun 13 '12 at 00:43
  • 1
    In addition, Windows GUI applications don't have "output" like that, anyway. What exactly are you trying to accomplish? – Ken White Jun 13 '12 at 00:47

3 Answers3

3

From the Wikipedia article:

In computer programming, standard streams are preconnected input and output channels between a computer program and its environment (typically a text terminal) when it begins execution. The three I/O connections are called standard input (stdin), standard output (stdout) and standard error (stderr).

As mentioned by Joe, the information written to standard in and out are typically chained together between console applications. The text displayed in windows applications does not typically follow this pattern, though they do have the 3 standard streams available to them, they just usually don't write to them.

CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
2

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.

rerun
  • 25,014
  • 6
  • 48
  • 78
  • Minor correction: They are mostly used to receive input and send output, not necessarily "to each other". Printing to the console and receiving input from the keyboard are perfectly common uses of `stdin` and `stdout`. – Ken White Jun 13 '12 at 00:49
1

The standard output stream is mostly for console output. For instance, if in python, you do

print('hello world')

It will print to the Standard Output Stream (also called stdout).

To do what you want to do, you'd need to open the notepad with a location in the arguments, ask the user to save the file somehow, then read the file the user saved.

roblabla
  • 113
  • 1
  • 10