#web端检测服务器程序运行,启动服务器程序,关闭服务器程序
import os import sys import time import win32com.client def check_exsit(process_name): WMI = win32com.client.GetObject('winmgmts:') processCodeCov = WMI.ExecQuery('select * from Win32_Process where Name like "%{}%"'.format(process_name)) if len(processCodeCov) > 0: return True else: return False def game_status(): examples = ["RSConsole.exe", "CSConsole.exe", "GSConsole.exe"] for example in examples : res = check_exsit(example) if not res : return False return True def game_stop(): examples = ["RSConsole.exe", "GSConsole.exe", "CSConsole.exe"] for example in examples : res = check_exsit(example) if res : os.system('taskkill /f /im ' + example) time.sleep( 1 ) return True def game_start(): examples = ["CSConsole.exe", "GSConsole.exe", "RSConsole.exe"] examples_path = {"CSConsole.exe" : "F:/Server_RC_ATT/WYYGame/Bin/x64/Debug", "GSConsole.exe" : "F:/Server_RC_ATT/WYYGame/Bin/x64/Debug/GSATT2", "RSConsole.exe" : "F:/Server_RC_ATT/WYYGame/Bin/x64/Debug"} for example in examples : cmd_line = 'start "' + example + '" /d "' + examples_path[example] + '" /MIN "' + example + '"' #需要注意在进程名字,路径加双引号 os.system(cmd_line) time.sleep( 5 ) return True if __name__ == '__main__': operationType = sys.argv[1] if "game_status" == operationType : print(game_status()) if "game_stop" == operationType : print(game_stop()) if "game_start" == operationType : game_stop() print(game_start())
php端調用
<?php $a = "game_start"; exec("python F:/Server_RC_ATT/WYYGame/Bin/x64/game_status.py $a", $out, $res); for($i = 0; $i < count($out); $i++) { echo $out[$i]; echo "<br>"; } echo $res; ?>