Problems with select() and stdin (solved)
INIGOSERNA
INIGOSERNA at terra.es
Wed Aug 21 07:43:23 EDT 2002
Thanks again Jeff,
I'm going to print your mail and staple it in page 159 of my 4-hours-ago
received copy of Python Cookbook ;-)
Iñigo
> If you don't want to read the full input upfront, you can use the
> following code to get the original stdin on a different file, then
> open the tty as standard input (untested):
>
> # Get a new Python file object which corresponds to the program's
> # original standard input but has a different fd (fileno)
> orig_stdin = os.fdopen(os.dup(0))
>
> # Create the terminal input
> new_stdin = open("/dev/tty")
>
> # Force it to be fd (fileno) 0
> if new_stdin.fileno() != 0 :
> os.dup2(new_stdin.fileno(), 0)
> new_stdin.close()
>
> # Now open sys.stdin on the new terminal input
> sys.stdin = os.fdopen(0)
>
> # initialize ncurses or whatever
> ...
More information about the Python-list
mailing list