python3 EOFError: EOF when reading a line

1.6k Views Asked by At

Need help with this, appreciate if someone can try to suggest a fix.

$ echo "print('This works fine')"|python3

This works fine.

But:

$ echo "input('This is NOT working! ')"|python3

This is the output received:

This is NOT working! Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError: EOF when reading a line
1

There are 1 best solutions below

5
On

It seems you just want to execute python commands inline from bash. For this task you can use this:

python3 -c "input('This also works)"

EDIT: If you want to use the pipe, you can just take the input from bash and pipe it to python, like this:

#!/bin/bash
read -p "Enter your name : " name
echo "x='$name';print('My name is', x)"|python3