From: Steven Baltakatei Sandoval Date: Fri, 27 Oct 2023 06:47:32 +0000 (+0000) Subject: feat(unitproc/python):Add py script to read stdin X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/f4b7fb50697f158e3f609c6b60fda57d7de47d00?ds=inline;hp=266a2b54f6db726f7dc7979cf64a0424124a2e8a feat(unitproc/python):Add py script to read stdin --- diff --git a/unitproc/python/bkt-read_stdin b/unitproc/python/bkt-read_stdin new file mode 100644 index 0000000..b41f7ab --- /dev/null +++ b/unitproc/python/bkt-read_stdin @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# Desc: Reads stdin +# Input: stdin (consumes) +# Output: stdout (newline delimited) +# Example: echo -e "foo\nbar\n" | python3 this_script.py +# Depends: Python 3.10.12 +# Version: 0.0.1 + +import sys + +def read_stdin(): + """Reads from stdin and outputs to stdout.""" + lines = [] + for line in sys.stdin: + # Remove trailing newline character + line = line.strip() + lines.append(line) + + # Print to stdout + for line in lines: + print(line) + +if __name__ == "__main__": + read_stdin()