Home

osStdout

os.Stdout is the standard output stream provided by Go's standard library. It is exposed as the exported variable Stdout in the os package and represents the process’s primary destination for textual output. In code, it is a pointer to an os.File, specifically a *os.File, that wraps the underlying file descriptor for standard output.

On POSIX systems, os.Stdout corresponds to file descriptor 1. On Windows, it maps to the system’s standard

Common usage patterns include writing program output directly to os.Stdout, or via fmt or bufio wrappers for

Note that os.Stdout is a real file handle for the process. Closing it is generally discouraged, as

output
handle.
The
underlying
type,
*os.File,
offers
methods
such
as
Write
and
WriteString,
and
can
be
used
with
I/O
utilities
that
accept
an
io.Writer,
such
as
fmt.Fprintln,
fmt.Fprintf,
or
bufio.Writer.
By
default,
writing
to
os.Stdout
appears
in
the
program’s
terminal
or
shell
where
the
program
was
invoked,
and
can
be
redirected
by
the
shell
to
a
file
or
another
process.
line-buffered
or
formatted
output.
It
is
typical
to
do
fmt.Fprintln(os.Stdout,
"message")
or
to
pass
os.Stdout
to
functions
that
accept
an
io.Writer.
If
buffered
output
is
desired,
developers
often
wrap
os.Stdout
with
a
buffered
writer
(e.g.,
bufio.NewWriter(os.Stdout))
to
improve
performance
for
many
small
writes.
it
prevents
further
output
and
may
disrupt
the
shell
or
other
components.
For
testing
or
redirection,
it
is
common
to
substitute
a
different
writer
or
use
interprocess
communication
rather
than
closing
the
global
Stdout.