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.
18 lines
912 B
18 lines
912 B
# -*- coding: utf-8 -*-
|
|
"""票 04:PowerShell Stop-Process 杀 34400(taskkill 静默失效的替代)。"""
|
|
import io, sys, subprocess, time
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
|
|
cmd = ['powershell', '-NoProfile', '-Command',
|
|
'try { Stop-Process -Id 34400 -Force -ErrorAction Stop; "STOPPED" } catch { $_.Exception.Message }']
|
|
try:
|
|
r = subprocess.run(cmd, capture_output=True, text=True, timeout=20)
|
|
print('rc=', r.returncode, '|', (r.stdout or '').strip(), '|', (r.stderr or '').strip()[:200])
|
|
except subprocess.TimeoutExpired:
|
|
print('powershell TIMEOUT —— 请手动杀 PID 34400')
|
|
sys.exit(2)
|
|
|
|
time.sleep(2)
|
|
r2 = subprocess.run(['netstat', '-ano'], capture_output=True, text=True, timeout=10)
|
|
listeners = [l.strip() for l in r2.stdout.splitlines() if 'LISTENING' in l and ':8080' in l]
|
|
print('[8080 after]', listeners if listeners else 'PORT-FREE')
|
|
|