[Python-de] 2004q3/005539.html
Gerhard Quell
gquell at skequell.de
Die Aug 17 18:31:36 CEST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hallo Hartmut,
~ hier mein Test und dessen Ausgabe, danach ist alles ok:
~ echo "1234567890" | ./getchar.py
~ Zeichen eingeben 31 32 33 34 35 36 37
Gruß
Gerhard
- -------------
Hartmut Fröls wrote:
| gquell at skequell.de wrote:
|
|> Hallo Leut,
|>
|> ~ versuchs mal so:
|>
|>
|> #!/usr/bin/env python
|> # testprogramm getchar
|>
|> import os, sys
|> import termios
|>
|> def getch():
|>
|> ~ fd = sys.stdin.fileno()
|> ~ if os.isatty(fd):
|>
|> ~ old=termios.tcgetattr(fd)
|> ~ new=termios.tcgetattr(fd)
|> ~ new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
|> ~ new[6] [termios.VMIN] = 1
|> ~ new[6] [termios.VTIME] =0
|> ~ try:
|> ~ termios.tcsetattr(fd, termios.TCSANOW, new)
|> ~ termios.tcsendbreak(fd,0)
|> ~ ch = os.read(fd,7) # vorher: 7
|> ~ finally:
|> ~ termios.tcsetattr(fd, termios.TCSAFLUSH, old)
|> ~ else:
|> ~ ch = os.read(fd,7)
|>
|> ~ return(ch)
|>
|> if __name__ == "__main__":
|> ~ print "Zeichen eingeben" ,
|> ~ cc=getch()
|> ~ for j in cc: print "%x" % ord(j),
|> # End getchar.py
|>
|>
|> Gruß Gerhard
|>
| Sorry, da war ich wohl missverständlich.
|
| Das Problem liegt nicht in dem termios-Zweig, sondern bei dem
| 2. read, wenn stdin nicht als tty erkannt wird !
|
|
|
|
|
| _______________________________________________
| python-de maillist - python-de at python.net
| http://python.net/mailman/listinfo/python-de
- --
- ------------------------------------------------------ skequell ------
~ Gerhard Quell Software & Knowledge Engineering
~ Schützenweg 3 eMail: gquell at skequell.de Fon: 0731-26400651
~ 89275 Elchingen web : http://www.skequell.de Fax: 0731-26400652
- --------------- pgp: 473EC53C - http://www.keyserver.net/en---------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFBIjLnvHbZD0c+xTwRAsADAJ0VluBgakdmgigSHvIPVIVy8SPzfQCffdqf
Nt2XyCtHanNY8ofp+Wscny0=
=O/GZ
-----END PGP SIGNATURE-----