It would be better if you explained what your goal is in this design. Maybe this can be simplified?
The problem with this script is that echo goes into the stdin encapsulating shell initiated by the note (...) . But inside the shell, stdin is redefined as heredoc sent to python , so it reads the script from stdin, which now comes from heredoc .
So you are trying to do something like this:
echo -e "Line One\nLine Two\nLine Three" | python <(cat <<HERE import sys print "stdout hi" for line in sys.stdin: print line.rstrip() print "stdout hi" HERE )
Conclusion:
stdout hi Line One Line Two Line Three stdout hi
Now the script is read from /dev/fd/<filehandle> , so stdin can be used by the echo pipe.
SOLUTION # 2
There is another solution. The script can be sent to python stdin as here-is-document, but then the input channel should be redirected to another file descriptor. To do this, the script uses a fdopen(3) similar function. I am not familiar with python , so I show a perl example:
exec 10< <(echo -e "Line One\nLine Two\nLine Three") perl <<'XXX' print "stdout hi\n"; open($hin, "<&=", 10) or die; while (<$hin>) { print $_; } print "stdout hi\n"; XXX
Here echo redirected to the file descriptor 10, which opens inside the script.
But the echo part can be removed (-1 fork ) using another heredoc :
exec 10<<XXX Line One Line Two Line Three XXX
MULTILINE SCIPRT
Or simply enter a multile script using the -c option:
echo -e "Line One\nLine Two\nLine Three"|python -c 'import sys print "Stdout hi" for line in sys.stdin: print line.rstrip() print "Stdout hi"'