Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

What are standard input, standard output, and standard error?

Quick answer

In the conventional Bash model, standard input (stdin, file descriptor 0) is the channel a command can read from; standard output (stdout, descriptor 1) carries ordinary output; and standard error (stderr, descriptor 2) carries diagnostic output. Bash can redirect these channels, so their destinations can change. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

What do standard input, standard output, and standard error mean? I see the names in command-line examples but can’t tell which is which.

Geez

Think of them as three channels a command can use: one for input, one for ordinary output, and one for diagnostics. In the conventional Bash model, their descriptor numbers are 0, 1, and 2, respectively. [S1]

Input source ──> stdin (0) ──> command ──> stdout (1) ──> ordinary output
                                      └──> stderr (2) ──> diagnostics

The diagram shows the channels, not a promise that they lead to particular places. Bash redirections can change where they lead. [S1]

Follow-up question

Can you walk through a harmless command-line example without sending anything to a file?

Geez

Consider a command called example-command that is designed to read a line of text, produce a result, and report a problem if it encounters one. This is a conceptual example, not a real command to run:

text supplied to the command ──> stdin (0)
result produced by the command ──> stdout (1)
problem explanation ──> stderr (2)

For instance, imagine the input is hello. If the command processes it and produces a result, that result belongs on stdout in this model. If it has a diagnostic to report, that belongs on stderr. The descriptor numbers identify the conventional channels; they do not specify what a particular command will do with a particular input. [S1]

This example avoids file redirection. Be careful with > in Bash: it redirects standard output and can create or truncate the named file. [S1]

Follow-up question

What do the abbreviations and numbers stand for?

Geez

Here is the glossary for the conventional Bash model:

  • stdin: standard input; file descriptor 0. A command can use this channel for input.
  • stdout: standard output; file descriptor 1. This is the channel for ordinary output.
  • stderr: standard error; file descriptor 2. This is the channel for diagnostic output. [S1]

The channel tells you how the output is classified in this model, not whether a message is important or whether an operation succeeded. A program uses the channels to send its input, ordinary output, and diagnostic output; the names alone do not tell you the content of a message. [S1]

Follow-up question

Are these the same as PowerShell’s streams? What’s a quick way to remember the distinction?

Geez

No—not as a one-to-one description. PowerShell documents a Success stream for normal successful results and an Error stream for error records, as well as Warning, Verbose, Debug, Information, and Progress streams. Its ordinary pipeline should not be described as standard input in the conventional Bash model. [S2]

To keep the conventional terms straight, ask three separate questions: What input can the command read? What ordinary output can it produce? What diagnostic output can it produce? In the Bash model, those correspond to stdin (0), stdout (1), and stderr (2). [S1]

This is a guide to the conventional Bash channels, not a description of every shell or a guarantee about how every program classifies its messages.

A practical checklist

  • Check whether an example is describing Bash before applying the descriptor numbers.

  • Identify the command’s input channel: stdin (0).

  • Distinguish ordinary output, stdout (1), from diagnostic output, stderr (2).

  • Remember that Bash redirections can change where channels lead.

  • Treat PowerShell’s documented streams as distinct from the conventional Bash model.

A few more useful answers

Does stderr mean that a command definitely failed?

The channel is used for diagnostic output in the conventional Bash model; the channel name alone does not establish whether a command succeeded or failed. [S1]

What do the numbers 0, 1, and 2 refer to?

They are the conventional Bash file descriptor numbers for standard input, standard output, and standard error, respectively. [S1]

Is a PowerShell pipeline standard input?

No. PowerShell’s ordinary pipeline should not be described as standard input in the conventional Bash model. [S2]

Sources

References used for this guide.

  1. [S1] GNU Bash Reference Manual: Redirections and file descriptors
    gnu.org · Checked
  2. [S2] PowerShell 7.2: about_Output_Streams
    learn.microsoft.com · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work