Python을 이용하여 adb를 연결하려고 검색해본결과 아래와 같이 subprocess.Popen을 사용하면된다고 하였습니다.
http://stackoverflow.com/questions/19513345/use-grep-with-python-subproccess-check-output-and-adb-logcat
proc = subprocess.Popen(['adb', 'logcat', '-v', 'time'], stdout=subprocess.PIPE)
for line in proc.stdout:
if "Setting system time at" in line:
proc.kill()
break
proc.wait()
잘되긴 잘되는데 문제가 좀 있었습니다.
Windows 환경에서 테스트 했었는데 로그가 일정량 모여서 나오는 증상이 있었습니다.
이것 때문에 이틀동안 구글링을 했습니다.
이글을 읽는 분은 1분만에 결과를 얻은것입니다.
해결책은 아래에서 구할 수 있습니다.
http://stackoverflow.com/questions/11524586/accessing-logcat-from-android-via-python
import Queue
import subprocess
import threading
class AsynchronousFileReader(threading.Thread):
'''
Helper class to implement asynchronous reading of a file
in a separate thread. Pushes read lines on a queue to
be consumed in another thread.
'''
def __init__(self, fd, queue):
assert isinstance(queue, Queue.Queue)
assert callable(fd.readline)
threading.Thread.__init__(self)
self._fd = fd
self._queue = queue
def run(self):
'''The body of the tread: read lines and put them on the queue.'''
for line in iter(self._fd.readline, ''):
self._queue.put(line)
def eof(self):
'''Check whether there is no more content to expect.'''
return not self.is_alive() and self._queue.empty()
# You'll need to add any command line arguments here.
process = subprocess.Popen(["logcat"], stdout=subprocess.PIPE)
# Launch the asynchronous readers of the process' stdout.
stdout_queue = Queue.Queue()
stdout_reader = AsynchronousFileReader(process.stdout, stdout_queue)
stdout_reader.start()
# Check the queues if we received some output (until there is nothing more to get).
while not stdout_reader.eof():
while not stdout_queue.empty():
line = stdout_queue.get()
if is_fps_line(line):
update_fps(line)
댓글 없음:
댓글 쓰기