服务器状态关闭,通过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端調用

$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 "
";

}

echo $res;

?>

标签:web,exe,return,服务器程序,程序运行,res,game,examples,example

来源: https://www.cnblogs.com/hailong88/p/13398849.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值