Created
October 27, 2012 16:55
-
-
Save saitoha/3965319 to your computer and use it in GitHub Desktop.
get DA1 report from terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os, termios, select | |
TIMEOUT=2 | |
stdin_fileno = sys.stdin.fileno() | |
backup = termios.tcgetattr(stdin_fileno) | |
new = termios.tcgetattr(stdin_fileno) | |
new[3] = new[3] &~ (termios.ECHO | termios.ICANON) | |
termios.tcsetattr(stdin_fileno, termios.TCSANOW, new) | |
try: | |
rfds = [stdin_fileno] | |
wfds = [] | |
xfds = [] | |
sys.stdout.write("\x1b[c") | |
sys.stdout.flush() | |
rfd, wfd, xfd = select.select(rfds, wfds, xfds, TIMEOUT) | |
if rfd: | |
data = os.read(stdin_fileno, 1024) | |
print "reply: ESC %s" % data[1:] | |
finally: | |
termios.tcsetattr(stdin_fileno, termios.TCSANOW, backup) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment