Python raw_input following sys.stdin.read () throws an EOFError

A similar question was asked before , but the answers offered a workaround that is not applicable to my situation.

The email is sent from mutt to script and read from STDIN:

message = sys.stdin.read() # message is parsed and URLs are printed as a list to choose from... selected_index = raw_input('Which URL to open?') 

I understand that raw_input () will get EOF to the left of read (), but is there a way to "reset" STDIN?

+7
source share
2 answers

Have you tried this:

 message = sys.stdin.read() sys.stdin = open('/dev/tty') selected_index = raw_input('Which URL to open?') 

This works on Linux; perhaps it will work for OSX as well.

+5
source

Try reset STDIN with sys.stdin.seek(0)

Link: http://docs.python.org/library/fileinput.html

0
source

All Articles