views:

38

answers:

2

I read about standard streams. My understanding is old fashioned programs that don't have GUI need some kind of user interface, too. So Operating System provide each of them with a console window, and the console window's out/input/err stream was mapped to the program's standard input/output/error stream. And thus these programs are called console application. And this mappings couldn't be modified by the programmer.

I am wondering, if my understanding above is correct, does GUI program have these standard streams also? I don't think it's necessary since GUI itself is a good user interface.

+3  A: 

I'm quoting the bottom of the article you linked to:

Graphical user interfaces (GUIs) rarely make use of the standard streams.

Some GUI programs, primarily on Unix, still write debug information to standard error.

Others may take files to operate from standard in, for example many Unix media players do so.

Therefore from the above quotes, you can see that yes they do, although they're rarely used.

"And this mappings couldn't be modified by the programmer."

This is incorrect - certainly on UNIX they can be - not sure about Windows. For example, you can close the standard output stream and redirect it to a file stream to get the output written to a file.

Andy Shellam
+1  A: 
  • This varies a lot based on your OS. Some will create a console if you run a "command line" app, some will connect the standard streams to the same streams as the process that started the program had.
  • You typically can change the stdout/in/err streams, it's very common to connect them to something else than the console in which they were run, like a pipe or file.
  • GUI programs typically have the stdout/err/in streams as well.
  • GUI programs rarly use those streams, perhaps except for debugging printfs during development.
  • GUI programs might redirect those streams to /dev/null or something similar that just discards data written to it.
nos
Thanks, nos. If I understand it right. A program has stdout/in/err and these threams can be connected to the console's out/in/err or not. Suppose I don't make such connection, can I write directly to the stdout stream of a program? could you give me some sample code snippet? C# would be better... Many thanks.
smwikipedia