Is it possible?: cat text.txt | python_script_which_also_gets_user_input.py

Robert M. Emmons RobMEmmons at cs.com
Sat Sep 4 22:46:51 EDT 2004


> I run in a problem with a script, that shall work similar like the c-program
> "most". It should be able to get some text on execution via a pipe but also
> is interactive by the user via the curses module (for scrolling and stuff).
> The problem is: if you call the script like that, you connect stdin to
> text.txt and any later keyboard input is ignored, since curses also reads
> from stdin.
> I have the rather blurry impression that this could be possible with
> threading or forking inside the script, but I nether did things like that
> before and am hopeful to get some cool advice from you experienced

I'm not sure, I've not tried this.  The suggestion I'd have is redirect 
the the input that curses reads to /dev/tty if you can figure out how to 
do that.

Python does have some redirection capability built in the the sys 
module, i.e. it's possible to separate sys.stdin and sys.__stdin__ and 
handle them sepratelty.  Just for tty direct IO, that would be easy.  I 
just don't know about curses, because it probably is outside of python.

Rob



More information about the Python-list mailing list