feat(unitproc/python):Add py script to read stdin
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Fri, 27 Oct 2023 06:47:32 +0000 (06:47 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Fri, 27 Oct 2023 06:47:32 +0000 (06:47 +0000)
unitproc/python/bkt-read_stdin [new file with mode: 0644]

diff --git a/unitproc/python/bkt-read_stdin b/unitproc/python/bkt-read_stdin
new file mode 100644 (file)
index 0000000..b41f7ab
--- /dev/null
@@ -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()