Yidir
Yidir

Reputation: 613

EOFError when input() after print() in SSH console

I got a strange behavior in my Python code. It runs fine in my Windows console

For example,

@cmd.exe : python file.py

Content of my file.py file

print("-------------------------- RANDOM STRING HERE! --------------------------------")
email = input()
print("-------------------------- RANDOM STRING HERE! --------------------------------")
name = input()
print("-------------------------- RANDOM STRING HERE! --------------------------------")
address = input()
print("-------------------------- RANDOM STRING HERE! --------------------------------")
print(email+name+address)

This same code doesn't work when I do:

curl ://filepath/file.py | sudo python3

in an a console under SSH. I already tried with PuTTY and Git Bash, but I am still getting the same error.

EOFError in SSH Console:

EOFError in SSH Console

I already tried to use sys.stdin, but it doesn't work as expected.

Upvotes: 3

Views: 244

Answers (1)

Jakuje
Jakuje

Reputation: 25956

No, really, you can't do that this way. Running

... | sudo python3

puts the script to the stdin so you can't use the stdin from that script any more.

But you can do it the other way round without a pipe using a temporary file:

curl ://filepath/file.py -o /tmp/script
sudo python3 /tmp/script

Or using process substitution (in Bash):

python3 <(curl ://filepath/file.py)

Upvotes: 2

Related Questions