[Tutor] changing sys.stdin to accept keyboard input

dman dsh8290@rit.edu
Sun, 3 Mar 2002 17:55:38 -0500


On Sun, Mar 03, 2002 at 09:36:07PM +0530, Prahlad Vaidyanathan wrote:
| Hi,
| 
| I have a script to extract URLs from an Email by piping the mail
| through it using the recently posted url_re regex (thanks Danny !).
| 
| Now, what I want to do is, after it has finished printing the links, I
| want it to wait for me to enter the number corresponding to a URL, so it
| can open this url using my browser, or save the link-name to a file so I
| can browse later.
| 
| So, my question right now is, how do I make it wait for input from me,
| even though sys.stdin here corresponds to the Email I am piping into the
| script. Right now, a simple raw_input() doesn't work because of the
| above reason.
| 
| Is there a way of changing sys.stdin to allow for input from the
| keyboard ?

I think it would be easier to re-design it so you don't need stdin to
be connected to different sources at different times.

Anyways, vim does this somehow by reading from stderr instead of
stdin.  From the vim manpage :

(list of command line args)
       -           The file to edit is read from stdin.  Commands
                   are read from stderr, which should be a tty.

If you were to run 
    echo "yo" | vim -
you would have vim running on your console with the text "yo" in a
new, unamed buffer.

If you grok C you could take a look at vim's source to see how Bram
implemented it.  I don't have time to look now.

HTH,
-D

-- 

Whoever gives heed to instruction prospers,
and blessed is he who trusts in the Lord.
        Proverbs 16:20