benj1
February 25th, 2010, 01:53 AM
im trying the write a python app that will take data from a pipe as well as non blocking input while running.
the problem is, is that it won't take input if something has been piped to it.
im assuming its because stdin is still connected to the pipe but ive also tried flushing stdin and modifying it to read from /dev/stdin, all to no avail.
any suggestions ?
EDIT:
ive made some progress, resetting stdin using
sys.stdin = open('/dev/tty', 'r')
and then calling a custom getch
def getch():
fd = sys.stdin.fileno()
tty_mode = tty.tcgetattr(fd)
tty.setcbreak(fd)
try:
ch = os.read(fd, 1)
finally:
tty.tcsetattr(fd, tty.TCSAFLUSH, tty_mode)
return ch
gets me basic functionality, although non ascii codes will be problematic
the curses builtin getch is still being problematic
the problem is, is that it won't take input if something has been piped to it.
im assuming its because stdin is still connected to the pipe but ive also tried flushing stdin and modifying it to read from /dev/stdin, all to no avail.
any suggestions ?
EDIT:
ive made some progress, resetting stdin using
sys.stdin = open('/dev/tty', 'r')
and then calling a custom getch
def getch():
fd = sys.stdin.fileno()
tty_mode = tty.tcgetattr(fd)
tty.setcbreak(fd)
try:
ch = os.read(fd, 1)
finally:
tty.tcsetattr(fd, tty.TCSAFLUSH, tty_mode)
return ch
gets me basic functionality, although non ascii codes will be problematic
the curses builtin getch is still being problematic