WSL PowerShell Stdin Consumption in Loops¶
When calling PowerShell from bash while-read loops, PowerShell can consume stdin meant for the loop.
The Problem¶
A while read loop processing files was only handling 1-2 iterations instead of all 8 files:
while IFS= read -r -d '' font_file; do
# Process file...
powershell.exe -NoProfile -Command "..." # This consumed remaining stdin!
done < <(find ... -print0)
The loop would exit early with no error - PowerShell silently consumed the process substitution's output.
The Solution¶
Redirect stdin to /dev/null for PowerShell commands inside loops:
Key Learnings¶
- PowerShell inherits stdin from the parent shell process
- In while-read loops using process substitution, this stdin is the loop's data source
- PowerShell can consume this data even when not explicitly reading input
- Always use `