stdin, stdout, and stderr
Every UNIX operating system has three files open all the time for its processes. Remember that UNIX considers everything, even a printer or a mouse, as a file. UNIX uses file descriptors, which are positive integer values, as an internal representation to access open files, which is much prettier than using long paths. So, by default, all UNIX systems support three special and standard filenames: /dev/stdin
, /dev/stdout
, and /dev/stderr
, which can also be accessed using the file descriptors 0
, 1
, and 2
, respectively. These three file descriptors are also called standard input, standard output, and standard error, respectively. Additionally, the file descriptor 0
can be accessed as /dev/fd/0
on a macOS machine and as both /dev/fd/0
and /dev/pts/0
on a Debian Linux machine.
Go uses os.Stdin
to access standard input, os.Stdout
to access standard output, and os.Stderr
to access standard error. Although you can still use /dev/stdin
, /dev/stdout
, and /dev/stderr...