Created
July 22, 2017 11:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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