def pre_process(strInput): global precmd_pattern if precmd_pattern == None: precmd_pattern = re.compile(r'dir|copy|cd', re.I) if precmd_pattern.match(strInput) != None: #os.system(strInput) p = os.popen(strInput) lines = p.readlines() for line in lines: print_n(code.gbk(line)) return True else: return False
def printMemInfo(f): proc_cmd = '''adb shell "dumpsys meminfo|grep com.txznet.txz"''' p = os.popen(proc_cmd) lines = p.readlines() if len(lines) > 0: print_n(lines[0]) if f != None: try: f.write("%s\n" % (now_time())) f.write(lines[0]) except Exception, e: print e
def run(self): buf = '' while True: if self.proc.msg_queue.empty(): if len(buf) != 0: self.print_cache(buf) buf = '' msg = self.proc.msg_queue.get() buf = "%s%s"%(buf, msg) if len(msg) == 0: self.print_cache(buf)#输出缓存数据 buf = '' break if not self.proc_exited: print_n('>') if self.file != None: try: self.file.close() self.file = None except Exception, e: pass
try: self.file.close() self.file = None except Exception, e: pass def print_cache(self, content): #两种可能不抛异常:1、不含中文。2、含中文、但是中文编码是utf8 try: content = content.decode('utf8').encode('gbk') except Exception, e: pass if self.file != None: self.file.write(content) else: print_n(content) def proc_wait(self): pass self.proc_exited = True class readThread(threading.Thread): def __init__(self, proc, target): threading.Thread.__init__(self) self.proc = proc def run(self): buffer = "" while True: