Windows Command Prompt Pipes Tutorial
last modified July 14, 2025
Pipes are a powerful feature in the Windows Command Prompt that allow you to chain multiple commands together. The pipe symbol (|) takes the output from one command and uses it as input for another command. This enables complex data processing by combining simple commands in sequence.
Pipes follow the Unix philosophy of creating small, focused tools that do one thing well. By combining these tools with pipes, you can solve complex problems efficiently. Pipes are particularly useful for filtering, sorting, and transforming command output without creating temporary files.
The pipe mechanism works by creating a temporary memory buffer between commands. The first command's standard output becomes the second command's standard input. Multiple pipes can be chained together to create processing pipelines of arbitrary complexity.
This tutorial will cover pipe fundamentals and demonstrate practical examples. You'll learn to combine commands effectively to process text, filter output, and automate tasks. These techniques are essential for efficient command-line usage and scripting.
Basic Pipe Concepts
Before diving into examples, let's define key pipe-related terms and concepts. Understanding these will help you use pipes effectively.
Pipe Symbol (|): The vertical bar character used to connect commands. It tells cmd to redirect the first command's output to the second command's input.
Standard Streams: Commands have three standard streams - input (stdin), output (stdout), and error (stderr). Pipes connect stdout of one command to stdin of another.
Filter Commands: Commands designed to process input from pipes. Examples include find, sort, and more. They typically read stdin when no filename is provided.
Redirection vs Pipes: Redirection (> or <) works with files, while pipes connect commands directly. Both can be combined in complex command sequences.
Pipeline: A sequence of commands connected by pipes. Each command in the pipeline processes the data and passes it to the next command.
Example 1: Filtering Command Output
The most common pipe use is filtering command output. This example shows how to display only relevant lines from verbose command output.
@echo off systeminfo | find "Total Physical Memory" ipconfig | find "IPv4"
This script demonstrates using find to extract specific information from command output. The pipe sends systeminfo and ipconfig output to find.
systeminfo | find "Total Physical Memory"
systeminfo generates extensive system data. The pipe sends this to find, which displays only lines containing "Total Physical Memory".
ipconfig | find "IPv4"
ipconfig shows network configuration. The pipe filters output to show only IPv4 addresses, hiding other network details.
C:\>filtering.bat Total Physical Memory: 16,290 MB IPv4 Address. . . . . . . . . . . : 192.168.1.100
The output shows only the filtered information. Your actual memory size and IP address will differ based on your system configuration.
Example 2: Sorting Command Output
Pipes can process and transform data. This example demonstrates sorting directory listings alphabetically.
@echo off dir /b | sort dir /b *.txt | sort /r
This script shows two sorting examples. The first sorts normally, while the second sorts in reverse order (/r) and filters for text files.
dir /b | sort
dir /b lists files in bare format (names only). The pipe sends this list to sort, which arranges them alphabetically.
dir /b *.txt | sort /r
Lists only .txt files and sorts them in reverse order. The /r switch makes sort display results from Z to A.
C:\>sorting.bat Documents Downloads Music Pictures Videos notes.txt report.txt todo.txt
The output shows sorted directory contents. First all files/dirs A-Z, then only .txt files Z-A. Your actual files will differ.
Example 3: Counting Lines in Files
Pipes can combine multiple commands for complex processing. This example counts lines matching a pattern across files.
@echo off type *.log | find /c "ERROR" find "WARNING" *.log | find /c /v ""
This script demonstrates two counting methods. The first counts ERROR lines in all .log files. The second counts WARNING lines using a different approach.
type *.log | find /c "ERROR"
type combines all .log files' contents. find /c counts lines containing "ERROR". The /c switch returns just the count.
find "WARNING" *.log | find /c /v ""
find first locates WARNING lines in .log files. The second find counts all lines (/v "" inverts empty string match, counting all lines).
C:\>counting.bat ---------- LOG1.LOG: 3 ---------- LOG2.LOG: 1 ---------- LOG3.LOG: 0 3 ---------- LOG1.LOG: 5 ---------- LOG2.LOG: 2 ---------- LOG3.LOG: 1 8
Output shows ERROR counts per file and total, then WARNING counts per file and total. Numbers depend on your log files.
Example 4: Processing Multiple Files
Pipes enable batch processing of multiple files. This example searches for text across files and formats the output.
@echo off findstr /s /i "important" *.txt *.ini | more findstr /s /i "password" *.txt *.ini | sort | more
This script searches recursively (/s) for text in files. The first command finds "important", the second finds "password" and sorts results.
findstr /s /i "important" *.txt *.ini | more
findstr searches all .txt and .ini files in current and subdirectories (/s). /i makes search case-insensitive. more paginates long output.
findstr /s /i "password" *.txt *.ini | sort | more
Searches for "password", sorts results alphabetically, then paginates. This three-command pipeline shows pipe chaining.
C:\>multifile.bat config.ini:admin_password=secret notes.txt:The important meeting is tomorrow settings.ini:important_flag=1 config.ini:admin_password=secret notes.txt:temp_password=12345 notes.txt:user_password=abcde
Output shows matching lines from files. The second command's output is sorted. Press space to page through more results.
Example 5: Complex Data Processing
This advanced example demonstrates multi-stage data processing using several piped commands to analyze system information.
@echo off systeminfo | findstr /i /r "memory.*[0-9]" | sort /r tasklist | findstr /i "chrome" | find /c /v ""
The script shows two complex pipelines. The first processes memory information, while the second counts Chrome processes.
systeminfo | findstr /i /r "memory.*[0-9]" | sort /r
systeminfo output goes to findstr, which finds memory-related lines with numbers (/r uses regex). Results are reverse-sorted.
tasklist | findstr /i "chrome" | find /c /v ""
tasklist shows running processes. findstr filters for Chrome instances. find counts them by counting all non-empty lines.
C:\>complex.bat Total Physical Memory: 16,290 MB Available Physical Memory: 8,142 MB Virtual Memory: Max Size: 18,690 MB Virtual Memory: Available: 10,242 MB Virtual Memory: In Use: 8,448 MB 5
Output shows memory information sorted in reverse order, followed by count of Chrome processes. Numbers vary by system.
Source
This tutorial covered Command Prompt pipes with practical examples. Pipes enable powerful command combinations for efficient data processing and system administration tasks.