How to Get Pipe Viewer (pv) for Windows: Cross-Platform Alternatives and Installation Guide


4 views

As a developer who frequently works across platforms, I've found pv (Pipe Viewer) to be one of those indispensable Unix tools that's conspicuously missing from Windows environments. While tools like grep, sed, and awk are readily available through MSYS2 or Cygwin, pv isn't typically included in these distributions.

Before exploring cross-platform solutions, let's examine native Windows options:

# PowerShell alternative for monitoring file copy progress
Get-ChildItem largefile.iso | ForEach-Object {
    $total = $_.Length
    $stream = [System.IO.File]::OpenRead($_.FullName)
    $buffer = New-Object byte[] 4096
    $count = $read = 0
    do {
        $read = $stream.Read($buffer, 0, $buffer.Length)
        $count += $read
        Write-Progress -Activity "Copying" -Status "Progress" 
            -PercentComplete ($count/$total*100)
    } while ($read -gt 0)
    $stream.Close()
}

The most seamless solution is using Windows Subsystem for Linux:

# In WSL terminal:
sudo apt update && sudo apt install pv

# Example usage:
pv largefile.bin | gzip > compressed.gz

For those preferring Cygwin or MSYS2:

# MSYS2 installation:
pacman -S pv

# Cygwin setup:
# Select pv from the package manager during installation

Some third-party builds are available:

# Example download via chocolatey:
choco install pv

# Or manual download from:
# https://www.ivarch.com/programs/pv.shtml (check for Windows builds)

Here's how pv can be useful in various scenarios:

# Monitor MySQL dump progress
pv database_dump.sql | mysql -u user -p database_name

# Track file transfer between servers
ssh user@source "cat bigfile.tar" | pv | ssh user@destination "cat > bigfile.tar"

# Monitor compression progress
tar cf - /big_directory | pv -s $(du -sb /big_directory | awk '{print $1}') | gzip > archive.tar.gz

When using pv in Windows environments, be aware of:

  • Throughput limitations in WSL for file operations
  • Potential buffering issues with Cygwin pipes
  • Performance overhead in MSYS2 for large data streams

If pv isn't suitable for your needs, consider:

  • Progress: A similar tool with Windows support
  • WinPV: A native Windows implementation
  • Process Explorer: For monitoring overall I/O

The Linux pv command doesn't have an official Windows port, but you can obtain it through several methods:


# Method 1: Using Cygwin (recommended)
1. Install Cygwin (https://www.cygwin.com/)
2. Select 'pv' package during installation
3. Add Cygwin's bin directory to PATH

# Method 2: Using WSL (Windows Subsystem for Linux)
1. Enable WSL: wsl --install
2. Install Ubuntu: wsl --install -d Ubuntu
3. sudo apt-get install pv

For native Windows solutions without Linux emulation:


# PowerShell alternative (progress display for file operations):
Get-Content input.txt | ForEach-Object -Begin {
    $i=0; $total=(Get-Item input.txt).Length
} -Process {
    $i += $_.Length
    Write-Progress -Activity "Processing" -PercentComplete ($i/$total*100)
    $_
} | Out-File output.txt

Advanced users can compile pv for Windows:


1. Install MinGW or MSYS2
2. Download pv source: https://www.ivarch.com/programs/pv.shtml
3. ./configure
4. make
5. make install

Common scenarios with pipe operations:


# Monitoring file transfer progress
tar -cf - ./dir | pv -s $(du -sb ./dir | awk '{print $1}') | gzip > dir.tar.gz

# Network throughput testing
dd if=/dev/zero bs=1M count=1000 | pv | nc -l -p 1234