From f4b7fb50697f158e3f609c6b60fda57d7de47d00 Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Fri, 27 Oct 2023 06:47:32 +0000 Subject: [PATCH] feat(unitproc/python):Add py script to read stdin --- unitproc/python/bkt-read_stdin | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 unitproc/python/bkt-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() -- 2.30.2