Oh boy, that makes sense! I struggled with this for the last hour, and finally, I understand, thank you both.
To provide a working alternative for the source program, you can do something like this:
$ echo hello | python <(cat <<END import sys for line in sys.stdin: print line END )
But be careful! If you put this in a file, the final END should touch the left gutter (no spaces). Otherwise, it will not analyze the โunexpected end of the file when looking for a suitable characterโ or something similar (in fact, it took me two more hours to find out when I started answering this question).
Explaining the code, what happens is that <<END ... END in combination with <(cat ...) creates a file (in /dev/fd ) so that it can be passed to python as if it were a real file. Quoting this explanation <(...) :
Replaces the process. It feeds the output of the command to FIFO, which can be read as a regular file.
There is another interesting answer on this question here .
source share