I'm trying to get the script that asks for the input to work when stdin is redirected. It could be that this is not even possible, but I would like to understand why. Here is an example:
$ echo 'q = raw_input("question ?"); print "\ngot: ", q' | python - < <(echo answer)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'answer' is not defined
I know I can get it to work with this:
$ python <(echo 'q = raw_input("question ?"); print "\ngot: ", q') < <(echo answer)
question ?
got: answer
but this is a process substitution. Is it possible to get it to work only with redirection?
python -cor a program saved in a file? Or does your script need to read something from stdin and prompt the user at the same time? Which would lead to the usual idea of giving the input from a file named at the script command line. Is there some reason you don't want that?