SNQ: stdin with both a pipe and keyboard

Michael Ressler ressler at cheetah.jpl.nasa.gov
Wed Jan 22 12:58:00 EST 2003


In article <1043212795.897835 at yasure>, Donn Cave wrote:
> 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
> 
> 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? ')
>    ...

Thanks - this is what I was looking for, and assumed it would be this
simple. My need is for a routine to take an email attachment from pine
using it's "pipe to Unix" command, and scp'ing it to a remote machine
with the ability to use a different filename. I'm sure there are a
billion better ways to do this (and I've come up with a few since I
first posted), but this dual stdin idea stuck in my craw and there had
to be some way to make it work. A quick perusal of the Python books by
Lutz et al. didn't immediately give me a solution, so I thought I'd ask.
Thanks again for all your (plural) inputs.

Mike




More information about the Python-list mailing list