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

Discussion in 'Python' started by schwerdy, Oct 27, 2003.

  1. schwerdy

    schwerdy Guest

    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
    schwerdy, Oct 27, 2003
    #1
    1. Advertising

  2. On 27 Oct 2003 01:21:22 -0800,
    (schwerdy) wrote:

    > 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

    --
    Heather Coppersmith
    That's not right; that's not even wrong. -- Wolfgang Pauli
    Heather Coppersmith, Oct 27, 2003
    #2
    1. Advertising

  3. schwerdy

    schwerdy Guest

    > 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 :-(
    schwerdy, Oct 27, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael W. Cocke
    Replies:
    1
    Views:
    408
    Jim Gibson
    Oct 9, 2003
  2. Replies:
    1
    Views:
    325
    Roedy Green
    Sep 16, 2005
  3. Guest

    Skript problem / display in 3 rows

    Guest, Jul 27, 2003, in forum: ASP General
    Replies:
    1
    Views:
    110
    Bullschmidt
    Jul 30, 2003
  4. Replies:
    0
    Views:
    89
  5. Replies:
    1
    Views:
    73
    Anno Siegel
    Feb 21, 2006
Loading...

Share This Page