# -*- coding: utf-8 -*-
import shutil
import os
file = 'D:\\Program Files (x86)\\Jenkins\\workspace\\maven_server\\coe-server\\target\\coe-server-0.0.1-SNAPSHOT.jar'
path = 'D:\\COE\\coe-service\\coe-server\\'
shutil.copy(file,path)
print('---------copy jar包 to coe-server ----')
#关闭coe-server
print ("获取coe-server的进程ID")
ip_path = 'D:\\COE\\coe-service\\coe-server\\ip.txt' #wmic process获取processid后,将返回结果存放到txt
os.system('wmic process where commandline="java -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-SNAPSHOT.jar" get processid /value > D:\\COE\\coe-service\\coe-server\\ip.txt')
#获取的txt格式不是utf-8,需要转换type
os.system('type D:\\COE\\coe-service\\coe-server\\ip.txt>D:\\COE\\coe-service\\coe-server\\ip2.txt')
#从txt中分割字符串,获取id值
with open('D:\\COE\\coe-service\\coe-server\\ip2.txt') as file_obj:
content = file_obj.read()
print(content.rstrip())
content = content.rstrip()
if content != None:
try:
id = content.split('=')[1]
print('id:'+id)
print ('taskkill /IM '+id+' /F')
os.system('taskkill /IM '+id+' /F')
print ('coe-server进程已关闭')
except Exception as e:
print ('coe-server进程已关闭',e)
else:
print ('coe-server进程已关闭')
---------------------------------
启服务命令:
java -jar coe-server-0.0.1-SNAPSHOT.jar
start /b java -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-SNAPSHOT.jar
windows查看java进程
wmic process 查看所有
wmic process get name,processid,caption,parentprocessid,threadcount/value
wmic process where caption="java.exe" get processid,caption,commandline /value
wmic process where commandline="java -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-
SNAPSHOT.jar" get name,processid,caption,commandline /value
wmic process where commandline="java -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-
SNAPSHOT.jar" get processid /value > D:\\COE\\coe-service\\coe-server\\ip.txt 将输入内容存放到txt
使用 进程名关闭
taskkill /im mspaint.exe /f
使用 进程id 关闭
taskkill /im 12555 /f