解决Appium IOS端口#8100被占用的问题,可以尝试以下代码示例:
lsof -i :8100
kill -9
其中,
是占用端口的进程ID。
import os
import subprocess
def kill_process_using_port(port):
lsof_command = subprocess.Popen(['lsof', '-i', f':{port}'], stdout=subprocess.PIPE)
grep_command = subprocess.Popen(['grep', 'LISTEN'], stdin=lsof_command.stdout, stdout=subprocess.PIPE)
awk_command = subprocess.Popen(['awk', '{print $2}'], stdin=grep_command.stdout, stdout=subprocess.PIPE)
output, _ = awk_command.communicate()
pid = output.decode('utf-8').strip()
if pid:
os.system(f'kill -9 {pid}')
print(f'Process with PID {pid} using port {port} has been terminated.')
else:
print(f'No process is using port {port}.')
kill_process_using_port(8100)
appium --port 8100 --session-override --relaxed-security
上述命令会强制关闭占用端口的进程并重启Appium。
请注意,在使用上述方法时,请确保占用端口的进程不是正在运行的重要进程。