From Wikipedia:
In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three I/O connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard streams abstract this."
As I understood from wiki the Stdin is traditionally the keyboard and the stdout is the monitor (output). But today what are these since most modern computers use GUI. For example, if I open cmd.exe of Linux Shell or whatever and I ran Python with this command:
# In cmd.exe
>>> import sys
>>> sys.stdout
<open file '<stdout>', mode 'w' at 0x000000000224B0C0>
A) I notice sys.stdout is a file (object) in memory, is it just an object created by Python interpreter? Or is sys.stdout physically stored in the a hard drive or any means of storage?
B) I think cmd.exe is a Win32 application, so does it have stdin, stdout or stderr and if so where are they? Are they just stored in memory?
They are called streams and not files for a reason: they represent sources or sinks of data. Sometimes data sent to a stream are stored in a file in disk, but sometimes the data is simply received by another program.
For example, when you pipe two commands together:
$ ls | sort
The standard output of the first command is connected to the standard input of the second command.
About where the standard streams are connected in a simple shell, the standard streams are connected to the virtual terminal program. In linux, it would be the program shell (xterm, gnome-terminal, kdeterminal...). In Windows it would be the console manager, that is created directly by a OS module (usually csrss.exe but details vary between Windows version).
Then, when you write to the standard output the written characters are shown on the screen, and when you read from the standard input, the terminal waits for keyboard input.
A file in Python is an abstraction of a file descriptor, which is just a low-level way of dealing with files and streams (and other things as well on *nix). In no way does it imply that there is anything on disk.
In addition, Windows applications don't have the standard streams available by default; the application must open them explicitly in order to make them available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With