Skript that reads from Unix Pipe _AND_ interacts by getkey()

S

schwerdy

Greetings to all Python fans :)

Is it possible to create a skript, that can read from a unix pipe
(eg.: "find -type f -name "*.ogg" | myscript.py"), _AND_ interact with
the user by waiting for keypress (eg.: getkey() funktion of a curses
screen)?

My tests failed: When I divert data via pipe to my skript and do
sys.stdin.read(), screen.getkey() always returns -1.

Has anyone an idea, how this issue can be solved? The "less" command
does exactly the same, so there should be a way.

Thanks in advance
Schwerdy
 
H

Heather Coppersmith

On 27 Oct 2003 01:21:22 -0800,
Is it possible to create a skript, that can read from a unix
pipe (eg.: "find -type f -name "*.ogg" | myscript.py"), _AND_
interact with the user by waiting for keypress (eg.: getkey()
funktion of a curses screen)?
My tests failed: When I divert data via pipe to my skript and do
sys.stdin.read(), screen.getkey() always returns -1.
Has anyone an idea, how this issue can be solved? The "less"
command does exactly the same, so there should be a way.

"less" interacts with the user through /dev/tty.

Regards,
Heather
 
S

schwerdy

Is it possible to create a skript, that can read from a unix pipe
(eg.: "find -type f -name "*.ogg" | myscript.py"), _AND_ interact with
the user by waiting for keypress (eg.: getkey() funktion of a curses
screen)?

I resolved this issue by myself, but I don't know if this is too Quick&Dirty:

import sys
lines = sys.stdin.readlines()
sys.stdin.close()
sys.stdin = open('/dev/tty','r')

that's it. The disadvantage of this is, that the skript now only runs on unix :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top