首先切换到这个目录,再执行增加和删除工作;
使用NoxConsole.exe,不要用NoxConsole;
执行完成后,一定要切回原来的路径,要不然很多函数的结果有问题;如aapt
def change_dir(app): ‘‘‘ 切换应用程序的目录 :param app: :return: ‘‘‘ try: cmd = ‘where ‘ + str(app) res = send_cmd(cmd=cmd) dir = "\\".join(res.split("\\")[:-1]) res = os.chdir(dir) path = os.getcwd() log.info("当前路径为:%s" %path) except Exception as err: raise Exception("change dir path fail: %s" % str(err)) def create_phone(num): ‘‘‘ 创建夜神模拟器 :return: ‘‘‘ cmd = ‘NoxConsole quitall‘ res = (os.popen(cmd)).read() time.sleep(1) pro_path = os.path.dirname(__file__) for i in range(int(num)): if i == 0: nox_name = ‘127.0.0.1:62001‘ else: nox_name = ‘127.0.0.1:‘ + str(i - 1 + 62025) # 因为创建新的虚拟机需要在NoxConsole的根目录下进行,所以先切换到该目录去 change_dir("NoxConsole") cmd = ‘NoxConsole.exe add -name:‘ + nox_name + ‘ -systemtype:5‘ res = (os.popen(cmd)).read() cmd = ‘NoxConsole.exe modify -name:‘ + nox_name + ‘ --resolution:1080,1920,270‘ res = (os.popen(cmd)).read() time.sleep(1) cmd = ‘NoxConsole.exe rename -name:‘ + nox_name + ‘ -title:‘ + nox_name res = (os.popen(cmd)).read() cmd = ‘NoxConsole.exe launch -name:‘ + nox_name res = (os.popen(cmd)).read() time.sleep(3) log.info(‘Virtual phone is launching, plaease wait 60s...‘) os.chdir(pro_path) time.sleep(Wait.launch_virtual_time)
原文:https://www.cnblogs.com/breakcircle/p/12509616.html