python实现模拟器的重启

import os
import time


class Dnconsole_leidian(object):
    '雷电模拟器启动与关闭'

    # 请根据自己电脑配置
    def __init__(self):
        self.console = r'D:\..\..\leidian\LDPlayer4\ldconsole.exe '

    def launch(self, index: int):
        '开启'
        cmd = self.console + 'launch --index ' + str(index)
        process = os.popen(cmd)
        result = process.read()
        print(result)
        process.close()

    def quit(self, index: int):
        '关闭'
        cmd = self.console + 'quit --index ' + str(index)
        process = os.popen(cmd)
        result = process.read()
        process.close()
        return result


# Dnconsole_leidian().quit(0)


class Dnconsole_mumu(object):
    '雷电模拟器启动与关闭'

    def __init__(self):
        # 请根据自己电脑配置
        self.console = r'D:\..\..\emulator\nemu9\EmulatorShell\NemuPlayer.exe '

    def quit_mumu(self):
        '关闭'
        # os.system('taskkill /f /im NemuPlayer.exe') # 需要管理员权限
        os.system("wmic process where name='NemuPlayer.exe' delete")  # 不需要管理员权限

    def launch_mumu(self):
        '启动'
        cmd = self.console + 'launch'  # --index ' + str(0)
        os.popen(cmd)
        # os.system(cmd)
        # result = process.read()
        # print(result)

    def run(self):
        self.quit_mumu()
        print('关闭MUMU模拟器成功')
        time.sleep(5)
        self.launch_mumu()
        print('打开MUMU模拟器成功')


Dnconsole_mumu().run()

你可能感兴趣的:(学习,python,开发语言)