diff --git a/examples/openthread/ot_ci_function.py b/examples/openthread/ot_ci_function.py index 4793b7cb7d..9582b5dc4b 100644 --- a/examples/openthread/ot_ci_function.py +++ b/examples/openthread/ot_ci_function.py @@ -410,12 +410,15 @@ def host_publish_service() -> None: def host_close_service() -> None: - command = "ps | grep avahi-publish-s | awk '{print $1}'" + command = 'ps aux | grep avahi-publish-s' out_bytes = subprocess.check_output(command, shell=True, timeout=5) out_str = out_bytes.decode('utf-8') - the_pid = re.findall(r'(\d+)\n', str(out_str)) - for pid in the_pid: + service_info = [line for line in out_str.splitlines() if 'testxxx _testxxx._udp' in line] + for line in service_info: + print('Process:', line) + pid = line.split()[1] command = 'kill -9 ' + pid + print('kill ', pid) subprocess.call(command, shell=True, timeout=5) time.sleep(1)