Back to Blog
Arnošt Havelka

Streams & Piping

Master data flow with Redirection and Pipes.

Start Interactive Lesson
Streams & Piping

Streams & Piping

Every command in Windows has three standard "streams":

  1. STDIN (0): Standard Input (Keyboard)
  2. STDOUT (1): Standard Output (Screen)
  3. STDERR (2): Standard Error (Screen)

By manipulating these streams, you can save potential errors to a log file, chain commands together, or automate input.

Usage:
command
operator
>
Redirects STDOUT to a file (Overwrite).
>>
Redirects STDOUT to a file (Append).
|
Pipes STDOUT of command 1 to STDIN of command 2.
2>
Redirects STDERR (Errors) to a file.

Common Scenarios

1. The Pipe (|)

Passes the output of one command as input to the next.

Example: List files and find specific ones.

dir | find "txt"

2. Output Redirection (>) and (>>)

Save results to a file.

Example: Save ipconfig details.

ipconfig > network_info.txt

3. Error Redirection (2>)

Separate clean output from error messages.

Example: Hiding errors when deleting non-existent files.

del non_existent_file.txt 2> nul

(Sending to nul effectively discards the output)

Real-World Examples

1. Sorting Output

List text files and sort them by name.

Command Prompt
C:\Users\User>dir /b *.txt | sort

2. Logging Errors Separately

Try to list a folder that doesn't exist, and save the error.

Command Prompt
C:\Users\User>dir MissingFolder 2> errors.log

Knowledge Check

1 / 3

Which number represents Standard Error (STDERR)?

References

These Microsoft Learn and Windows documentation links provide authoritative details for the commands used in this article.

Up Next

Network Basics

Master Ipconfig, Ping, and Tracert.