Skip to content

Instantly share code, notes, and snippets.

@LoveIsGrief
Created July 22, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LoveIsGrief/89237492606ab6ce2e7cef2fbc8eb7be to your computer and use it in GitHub Desktop.
Save LoveIsGrief/89237492606ab6ce2e7cef2fbc8eb7be to your computer and use it in GitHub Desktop.
Script to copy stdin to stdout and stderr since it's not easily possible in bash
#!/usr/bin/python3 -u
"""
Script to copy stdin to stdout and stderr since it's not easily possible in bash
Example usage:
# This will download a page and discard it (but it could be saved)
# and pipe the progress for further processing
# It'll still be visible thanks to in2outerr.py
# but tr will still be able to process it
curl https://duckduckgo.com 2>&1 >/dev/null | ./in2outerr.py | tr -s " " "," > /tmp/progress
"""
import sys
try:
# Why 64 bytes? I dunno, it seems to work better than small numbers like 1,2,3,4
# Maybe somebody else know's why
input = sys.stdin.buffer.read(64)
while input:
sys.stdout.buffer.write(input)
sys.stderr.buffer.write(input)
input = sys.stdin.buffer.read(64)
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment