import winrm
wintest = winrm.Session('http://47.103.144.112:5985/wsman', auth=("administrator", "xxxxx"))
# # 9068为远程运行python进程pid
# r = wintest.run_ps(r"""cd C:\Users\Administrator\Documents\GitHub\pytdx-Ycyj\ycyj_kline
# python app.py
# """) # 会卡住,线程单独执行,线程关闭后远程不会关闭
# pprint(r.std_out)
##################################
# 1、查看某个进程操作:
# netstat -aon|findstr xxx (xxx端口号)
# 2、关闭该进程:
# taskkill -f -pid aaa(aaa为该端口的进程pid号)
r = wintest.run_ps('''netstat -aon|findstr 80''')
out_str = r.std_out.decode('utf-8')
print(out_str)
import re
matchObj = re.search(r'([0-9]{2,}\r\n)', out_str)
if matchObj:
print('pid:', matchObj.group(1))