Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cr0hn/python-pipes
Helpers to manage stdin / stdout and UNIX pipes
https://github.com/cr0hn/python-pipes
pipeline stderr stdin stdout unix
Last synced: about 2 months ago
JSON representation
Helpers to manage stdin / stdout and UNIX pipes
- Host: GitHub
- URL: https://github.com/cr0hn/python-pipes
- Owner: cr0hn
- License: bsd-3-clause
- Created: 2020-05-06T12:54:48.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-20T10:04:18.000Z (over 4 years ago)
- Last Synced: 2024-10-06T19:34:45.183Z (3 months ago)
- Topics: pipeline, stderr, stdin, stdout, unix
- Language: Python
- Size: 10.7 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Python pipes
============This projects allow to read stdin and detect if input data comes from a UNIX pipe and if the output is connected to a UNIX pipe.
Install
-------.. code-block:: console
> pip install python-pipes
How to use
----------Basic example of a tool that read from info stdin:
.. code-block:: python
# file: basic_example.py
from python_pipes import read_stdin_linesdef main():
for is_stdin_pipe, is_stdout_pipe, line in read_stdin_lines():
print("Input connected to pipe: ", is_stdin_pipe)
print("Output connected to pipe: ", is_stdout_pipe)
print("Line read: ", line)if __name__ == '__main__':
main()Results depending of how to execute them:
.. code-block:: console
$ python basic_example.py
Input connected to pipe: False
Output connected to pipe: False
Line read: None
$
$ echo "hello" | python basic_example.py
Input connected to pipe: True
Output connected to pipe: False
Line read: hello
$
$ echo "hello" | python basic_example.py | awk '{print $0}'
Input connected to pipe: True
Output connected to pipe: True
Line read: hello