SNQ: stdin with both a pipe and keyboard

Donn Cave donn at drizzle.com
Wed Jan 22 00:20:00 EST 2003


Quoth Michael Ressler <ressler at cheetah.jpl.nasa.gov>:
| Stupid newbie question: I'm trying to cobble together a little routine
| that will accept a bunch of data presented to it on stdin, then ask for
| a filename to save it to. Something like
|
| cat datafile | transfer_file
|
| where "transfer_file" asks "What destination?" and expects me to type in.
|
| I've been using sys.stdin.read() to suck in the data, but if I then use
| raw_input() or something like it to ask for the filename, I get an EOF
| error; like raw_input() was already expecting the keyboard text to
| be there without waiting for it.

Something like this may work, as far as the problem statement goes -

   data = suck_in_data();
   sys.stdin = open('/dev/tty', 'r')
   fname = raw_input('What destination? ')
   ...

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list