From 0827fafb44900a6116baaccadab415b3f96a0c53 Mon Sep 17 00:00:00 2001 From: Brennan Taylor Date: Tue, 15 Jul 2014 12:51:06 -0700 Subject: [PATCH] When there is data on stdin we use it instead of adb --- pidcat.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pidcat.py b/pidcat.py index 8ad02bd..0cf7b19 100755 --- a/pidcat.py +++ b/pidcat.py @@ -22,11 +22,11 @@ limitations under the License. # Package filtering and output improvements by Jake Wharton, http://jakewharton.com import argparse +import sys import re import subprocess from subprocess import PIPE - LOG_LEVELS = 'VDIWEF' LOG_LEVELS_MAP = dict([(LOG_LEVELS[i], i) for i in range(len(LOG_LEVELS))]) parser = argparse.ArgumentParser(description='Filter logcat by package name') @@ -158,13 +158,23 @@ adb_command.append('logcat') # Clear log before starting logcat if args.clear_logcat: adb_clear_command = list(adb_command) - adb_clear_command.append('-c') + adb_clear_command.append('-c') adb_clear = subprocess.Popen(adb_clear_command) while adb_clear.poll() is None: pass -adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) +# This is a ducktype of the subprocess.Popen object +class FakeStdinProcess(): + def __init__(self): + self.stdout = sys.stdin + def poll(self): + return None + +if sys.stdin.isatty(): + adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE) +else: + adb = FakeStdinProcess() pids = set() last_tag = None app_pid = None