Home > other >  Popen executed after the tail command, some content is not returned, but the sync command line direc
Popen executed after the tail command, some content is not returned, but the sync command line direc

Time:04-23

Def search_syslog_new (self, syslog_re, timeout=150, search_res={}, begin_line=0) :
Start_time=time. Time ()
While True:
Adb_cmd="{0} the adb - s shell tail - F - n 10 syslog. Log | grep - line - buffered 'signal=trans, message='". The format (device_name)
Return_code=Popen (adb_cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
Log_lines=return_code. Stdout. Readlines (10)
Print (' log_content_is log_lines)
For the line in the range (begin_line, len (log_lines) :
If re.com running (syslog_re). The search (log_lines [the line]. Decode (' utf-8)) is not None:
# the callback function processing
# print (' log_content_is, log_lines [the line]. Decode (' utf-8))
If (search_res) :
Search_res [' search_groups]=re.com running (syslog_re). The search (log_lines [the line]. Decode (' utf-8 ')). The groups ()
Print (search_res [' search_groups'])
Print (re.com running (syslog_re). The search (log_lines [the line]. Decode (' utf-8)))
# return True
# time. Sleep (0.1)
If (time. Time () & gt; Start_time + float (timeout)) :
Print (" search syslog for {} seconds, the timeout ". The format (timeout))
Break
Return False

Syslog. The log content is continuously added, by performing the above method with content print (' log_content_is' log_lines) returns the results sometimes lack a part lines
But synchronization on the command line directly execute tail - F - n 10 syslog. Log | grep - line - buffered 'signal=trans, message=' corresponding results are complete, no missing
  • Related