Why Does Python Exit Immediately When I Pipe Code In With Echo But Not With Cat?
#!/bin/bash echo 'print('Hello 1')' | python3 cat | python3 -u <
Solution 1:
You aren't using cat. You're using a here-doc, and cat is waiting for input separately. Just remove the cat |
and try it again.
echo"print('Hello 1')" | python3
python3 -u <<EOF
print('Hello 2')
EOFecho"print('Hello 3')" | python3
cat, the way you are using it, would pipe its stdin to its stdout, becoming the stdin for the proc on the other side of the pipe, but you also defined a <<EOF
here-doc which takes precedence and ignores cat
's empty output.
cat is still waiting for input though. Once you hit return it (via OS magic) tries and realizes no one is listening on the pipe, and exits.
As an aside, you could also use a here-string, like this:
python3 <<< "print('Hello 2')"
Post a Comment for "Why Does Python Exit Immediately When I Pipe Code In With Echo But Not With Cat?"