python-pipes

Helpers to manage stdin / stdout and UNIX pipes


Keywords
unix, pipes, stdin, stderr, pipeline, stdout
License
OSET-PL-2.1
Install
pip install python-pipes==0.0.4

Documentation

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

> pip install python-pipes

How to use

Basic example of a tool that read from info stdin:

# file: basic_example.py
from python_pipes import read_stdin_lines

def 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:

$ 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