mirror of
https://github.com/openharmony/test_xdevice.git
synced 2026-07-19 18:23:38 -04:00
@@ -103,14 +103,14 @@ def is_proc_running(pid, name=None):
|
||||
stdout=subprocess.PIPE, shell=False)
|
||||
else:
|
||||
# /bin/ps -ef | /bin/grep -v grep | /bin/grep -w pid
|
||||
proc_sub = subprocess.Popen(["/bin/ps", "-ef"],
|
||||
proc_sub = subprocess.Popen(["ps", "-ef"],
|
||||
stdout=subprocess.PIPE,
|
||||
shell=False)
|
||||
proc_v_sub = subprocess.Popen(["/bin/grep", "-v", "grep"],
|
||||
proc_v_sub = subprocess.Popen(["grep", "-v", "grep"],
|
||||
stdin=proc_sub.stdout,
|
||||
stdout=subprocess.PIPE,
|
||||
shell=False)
|
||||
proc = subprocess.Popen(["/bin/grep", "-w", "%s" % pid],
|
||||
proc = subprocess.Popen(["grep", "-w", "%s" % pid],
|
||||
stdin=proc_v_sub.stdout,
|
||||
stdout=subprocess.PIPE, shell=False)
|
||||
(out, _) = proc.communicate()
|
||||
|
||||
+34
-30
@@ -118,8 +118,8 @@ def is_proc_running(pid, name=None):
|
||||
list_command = ["C:\\Windows\\System32\\tasklist"]
|
||||
find_command = ["C:\\Windows\\System32\\findstr", "%s" % pid]
|
||||
else:
|
||||
list_command = ["/bin/ps", "-ef"]
|
||||
find_command = ["/bin/grep", "%s" % pid]
|
||||
list_command = ["ps", "-ef"]
|
||||
find_command = ["grep", "%s" % pid]
|
||||
proc = _get_find_proc(find_command, list_command)
|
||||
(out, _) = proc.communicate()
|
||||
out = get_decode(out).strip()
|
||||
@@ -537,37 +537,41 @@ def check_path_legal(path):
|
||||
|
||||
|
||||
def get_local_ip():
|
||||
sys_type = platform.system()
|
||||
if sys_type == "Windows":
|
||||
_list = socket.gethostbyname_ex(socket.gethostname())
|
||||
_list = _list[2]
|
||||
for ip_add in _list:
|
||||
if ip_add.startswith("10."):
|
||||
return ip_add
|
||||
try:
|
||||
sys_type = platform.system()
|
||||
if sys_type == "Windows":
|
||||
_list = socket.gethostbyname_ex(socket.gethostname())
|
||||
_list = _list[2]
|
||||
for ip_add in _list:
|
||||
if ip_add.startswith("10."):
|
||||
return ip_add
|
||||
|
||||
return socket.gethostbyname(socket.getfqdn(socket.gethostname()))
|
||||
elif sys_type == "Darwin":
|
||||
hostname = socket.getfqdn(socket.gethostname())
|
||||
return socket.gethostbyname(hostname)
|
||||
elif sys_type == "Linux":
|
||||
real_ip = "/%s/%s" % ("hostip", "realip")
|
||||
if os.path.exists(real_ip):
|
||||
srw = None
|
||||
try:
|
||||
import codecs
|
||||
srw = codecs.open(real_ip, "r", "utf-8")
|
||||
lines = srw.readlines()
|
||||
local_ip = str(lines[0]).strip()
|
||||
except (IOError, ValueError) as error_message:
|
||||
LOG.error(error_message)
|
||||
return socket.gethostbyname(socket.getfqdn(socket.gethostname()))
|
||||
elif sys_type == "Darwin":
|
||||
hostname = socket.getfqdn(socket.gethostname())
|
||||
return socket.gethostbyname(hostname)
|
||||
elif sys_type == "Linux":
|
||||
real_ip = "/%s/%s" % ("hostip", "realip")
|
||||
if os.path.exists(real_ip):
|
||||
srw = None
|
||||
try:
|
||||
import codecs
|
||||
srw = codecs.open(real_ip, "r", "utf-8")
|
||||
lines = srw.readlines()
|
||||
local_ip = str(lines[0]).strip()
|
||||
except (IOError, ValueError) as error_message:
|
||||
LOG.error(error_message)
|
||||
local_ip = "127.0.0.1"
|
||||
finally:
|
||||
if srw is not None:
|
||||
srw.close()
|
||||
else:
|
||||
local_ip = "127.0.0.1"
|
||||
finally:
|
||||
if srw is not None:
|
||||
srw.close()
|
||||
return local_ip
|
||||
else:
|
||||
local_ip = "127.0.0.1"
|
||||
return local_ip
|
||||
else:
|
||||
return "127.0.0.1"
|
||||
except Exception as error:
|
||||
Log.debug("Get local ip error: %s, skip!" % error)
|
||||
return "127.0.0.1"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user