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 your mouse, as a file. UNIX uses file descriptors, which are positive integer values, as an internal representation for accessing 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 file descriptors 0
, 1
, and 2
, respectively. These three file descriptors are also called standard input, standard output, and standard error, respectively. Additionally, 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
for accessing standard input, os.Stdout
for accessing standard output, and os.Stderr
for accessing standard error. Although you can still use /dev/stdin
, /dev/stdout...