gbr gbr - 1 year ago 66
Python Question

How to make a python script "pipeable" in bash?

I wrote a script and I want it to be pipeable in bash. Something like:

echo "1stArg" |

It's possible? How?

Answer Source

See this simple

import sys

if __name__ == "__main__":
    for line in sys.stdin:
        sys.stderr.write("DEBUG: got line: " + line)


ls | python 2>debug_output.txt | sort


debug_output.txt content:

DEBUG: got line:
DEBUG: got line:
DEBUG: got line: