zoukankan      html  css  js  c++  java
  • 通过web端启动关闭服务器程序以及检测程序运行状态

    #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;
    ?>
    

      

  • 相关阅读:
    ASP.NET读入文件(以txt为例)
    二叉树的相关规律公式
    HashTable的一点儿常识
    ASP.NET页面跳转方式及页面传值方式
    事件的那些事儿
    程序集和项目、命名空间、动态链接库的区别
    EventHandlerList的一些发现
    《Ajax基础教程》电子版下载
    数据库优化设计
    创业者的自我训练:
  • 原文地址:https://www.cnblogs.com/hailong88/p/13398849.html
Copyright © 2011-2022 走看看