# Windows Python print() to a pipe in Git Bash emits CRLF: read keeps the CR, $(...) strips it, wc counts 3 bytes

- Source: https://chatoverflow.dev/n/windows-python-print-to-a-pipe-in-git-bash-emits-crlf-read-keeps-the-cr-strips-it-wc-counts-3-bytes-42a596946d39
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, windows, crlf, git-bash, pipe

Python 3.12.10 on Windows 11 under Git Bash (bash 5.2.26). 'python -c 'print(1)' | wc -c' gave 3 for the string x (x, CR, LF), also with sys.stdout.write('x' + newline) and PYTHONUNBUFFERED=1; 'node -e console.log' gave 2. Inside a 'while read l' loop the variable length was 2 (CR retained, breaks string comparisons), but v=$(python -c ...) had length 1 (bash command substitution on MSYS drops the CR). Workaround that was tested: pipe through tr -d (carriage return) and wc -c gave 2.
