标签:turn 自动 test blog col os.path local false sign
正文
#!/user/bin/python #coding=gbk #coding=utf-8 #-*- coding: UTF-8 -*- import time import win32api import os #启动SERVER功能函数 def startServer(serverType): if serverType == "G": serverType_Dir = "GServer" serverType_Name = "GServer.exe" serverType_LogDir = "D:\server\GServer.log" elif serverType == "M": serverType_Dir = "MServer" serverType_Name = "MServer.exe" serverType_LogDir = "E:\Tools\Script\MGserverManage\dist\GServer.log", "a+" g = os.walk("D:\\Server\\" + serverType_Dir) def startGame(): try: normal = win32api.ShellExecute(0, ‘open‘, serverType_Name , ‘‘, ‘‘, 0) return normal except: return False for path, a, filelist in g: for filename in filelist: if filename == serverType_Name: dir = os.path.join(path) os.chdir(dir) test = startGame() if test == False: #f = open("E:\Tools\Script\MGserverManage\dist\GServer.log", "a+") f = open(serverType_LogDir,"a+") errorDir = os.path.join(path, filename) f.write(serverType_Dir + "路径" + errorDir + "启动失败\t\t" + time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time.time())) + "\n") f.close() print((errorDir) + "启动失败,请查看日志文件") else: print(os.path.join(path, filename) + "启动成功") time.sleep(2) #停止SERVER功能函数 def stopServer(serverType): if serverType == "M": serverType_Name = "MServer.exe" command = "taskkill /f /im " + serverType_Name os.system(command) elif serverType == "G": serverType_Name = "GServer.exe" command = "taskkill /f /im " + serverType_Name os.system(command) print ("------------------------------------------------") print (" 1 启动 GSERVER" ) print (" 2 启动 MSERVER" ) print (" 3 启动 GSERVER + MSERVER" ) print (" 4 停止 GSERVER" ) print (" 5 停止 MSERVER" ) print (" 6 停止 GSERVER + MSERVER" ) print ("-------------------------------------------------") num = int(input("请输入序号: ")) if num == 1: startServer("G") print("所有GServer启动完成......") print("启动失败的GServer日志写入中......") elif num == 2: startServer("M") print("所有MServer启动完成") print("启动失败的MServer日志写入中......") elif num == 3: startServer("M") print("所有MServer启动完成,3秒后启动GServer") time.sleep(3) startServer("G") print("所有GServer启动完成") print("启动失败的GServer和MServer日志写入中......") elif num == 4: stopServer("G") print("GSERVER已停止运行,5秒后程序自动退出") elif num == 5: stopServer("M") print("MSERVER已停止运行,5秒后程序自动退出") elif num == 6: stopServer("M") stopServer("G") print("所有MSERVER,GSERVER 已停止运行,5秒后程序自动退出") else: print("谨慎操作!!!请输入正确的序号.5秒后程序自动退出,请重新打开 ") print("......5秒后程序将自动退出......")
标签:turn 自动 test blog col os.path local false sign
原文地址:http://www.cnblogs.com/winter-shadow/p/7687815.html