NOTE: Many of the same questions have been asked about python raw_input() in sublime text. This question is NOT about sublime. The python code is called in Windows command prompt which unlike the sublime terminal does support interactive inputs.
I have a python program that takes user input with the built-in function raw_input(). See below.
def password_score():
pwd = raw_input('Enter a password: ')
gname = raw_input('Enter your first name: ')
...
I call the program in cmd by
echo password_score()|python -i a06q1.py
where a06q1.py is the file name. The path of the python directory has been added to system variable %PATH%
temporarily. I am in the directory of the file. My operating system is Windows 7. I am using python 2.6. The same command has worked until now.
Then cmd returns
File "<stdin>", line 1, in <module>
File "a06q1.py", line 27, in password_score
pwd = raw_input(p_prompt)
EOFError: EOF when reading a line
Is there a way to get around it within cmd?
EDIT: I just tried in on an iOS terminal too. With the same command as in cmd (with quotes), it returns the same error. Is there anything wrong about the command line I used? Thank you!
EDIT: Sebastian's answer solves the problem. The command should adapt to windows as follows.
printf "a06q1.password_score()\n'arg1\n'arg2"|python -i -c "import a06q1"
The single quotes succeeding \n
can be replaced by spaces. They separate multiple inputs.