From d5cdeeffbd086bf52e20bde403b9a22aa9395449 Mon Sep 17 00:00:00 2001 From: deveco_test Date: Tue, 26 Jul 2022 14:27:33 +0800 Subject: [PATCH] fix mac bug Signed-off-by: deveco_test --- .../src/xdevice_extension/_core/utils.py | 22 +++++++++++++++---- src/xdevice/_core/utils.py | 7 ++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/extension/src/xdevice_extension/_core/utils.py b/extension/src/xdevice_extension/_core/utils.py index d9108ef..a27010c 100644 --- a/extension/src/xdevice_extension/_core/utils.py +++ b/extension/src/xdevice_extension/_core/utils.py @@ -101,18 +101,32 @@ def is_proc_running(pid, name=None): proc = subprocess.Popen(["C:\\Windows\\System32\\findstr", "%s" % pid], stdin=proc_sub.stdout, stdout=subprocess.PIPE, shell=False) - else: + elif platform.system() == "Linux": # /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid - proc_sub = subprocess.Popen(["ps", "-ef"], + proc_sub = subprocess.Popen(["/bin/ps", "-ef"], stdout=subprocess.PIPE, shell=False) - proc_v_sub = subprocess.Popen(["grep", "-v", "grep"], + proc_v_sub = subprocess.Popen(["/bin/grep", "-v", "grep"], stdin=proc_sub.stdout, stdout=subprocess.PIPE, shell=False) - proc = subprocess.Popen(["grep", "-w", "%s" % pid], + proc = subprocess.Popen(["/bin/grep", "-w", "%s" % pid], stdin=proc_v_sub.stdout, stdout=subprocess.PIPE, shell=False) + elif platform.system() == "Darwin": + # /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid + proc_sub = subprocess.Popen(["/bin/ps", "-ef"], + stdout=subprocess.PIPE, + shell=False) + proc_v_sub = subprocess.Popen(["/usr/bin/grep", "-v", "grep"], + stdin=proc_sub.stdout, + stdout=subprocess.PIPE, + shell=False) + proc = subprocess.Popen(["/usr/bin/grep", "-w", "%s" % pid], + stdin=proc_v_sub.stdout, + stdout=subprocess.PIPE, shell=False) + else: + raise Exception("Unknown system environment.") (out, _) = proc.communicate() out = get_decode(out).strip() LOG.debug("check %s proc running output: %s", pid, out) diff --git a/src/xdevice/_core/utils.py b/src/xdevice/_core/utils.py index 7969d5e..cf169ea 100644 --- a/src/xdevice/_core/utils.py +++ b/src/xdevice/_core/utils.py @@ -117,9 +117,12 @@ def is_proc_running(pid, name=None): if platform.system() == "Windows": list_command = ["C:\\Windows\\System32\\tasklist"] find_command = ["C:\\Windows\\System32\\findstr", "%s" % pid] + elif platform.system() == "Darwin": + list_command = ["/bin/ps", "-ef"] + find_command = ["/usr/bin/grep", "%s" % pid] else: - list_command = ["ps", "-ef"] - find_command = ["grep", "%s" % pid] + list_command = ["/bin/ps", "-ef"] + find_command = ["/bin/grep", "%s" % pid] proc = _get_find_proc(find_command, list_command) (out, _) = proc.communicate() out = get_decode(out).strip()