You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
1.0 KiB

7 days ago
# -*- coding: utf-8 -*-
"""票 04:杀全部 java 进程(带超时,Stop-Process 优先)。"""
import io, sys, subprocess, time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
# 找 PID
r = subprocess.run(['tasklist'], capture_output=True, text=True, timeout=10)
pids = [l.split()[1] for l in r.stdout.splitlines() if l.lower().startswith('java')]
print('java pids:', pids)
if not pids:
sys.exit(0)
ps = '; '.join(f'Stop-Process -Id {p} -Force' for p in pids)
try:
r2 = subprocess.run(['powershell', '-NoProfile', '-Command', ps],
capture_output=True, text=True, timeout=20)
print('rc=', r2.returncode, (r2.stdout or '').strip()[:100], (r2.stderr or '').strip()[:150])
except subprocess.TimeoutExpired:
print('powershell TIMEOUT')
time.sleep(2)
r3 = subprocess.run(['tasklist'], capture_output=True, text=True, timeout=10)
left = [l.split()[1] for l in r3.stdout.splitlines() if l.lower().startswith('java')]
print('java pids after:', left if left else 'NONE')