# -*- coding: utf-8 -*- """票 04:杀旧进程,结果写文件(终端 stdout 通道异常时的替代)。""" import subprocess, time out = [] r = subprocess.run(['taskkill', '/F', '/T', '/PID', '37420'], capture_output=True, text=True, shell=False) out.append(f'rc={r.returncode}') out.append(f'out={r.stdout!r}') out.append(f'err={r.stderr!r}') time.sleep(3) r2 = subprocess.run(['netstat', '-ano'], capture_output=True, text=True, shell=False) listeners = [l for l in r2.stdout.splitlines() if ':8080' in l and 'LISTENING' in l] out.append('listeners=' + (';'.join(listeners) if listeners else 'NONE-PORT-FREE')) open(r'e:\code\crm-backend-matt\.scratch\opportunity-bugfix\t04-kill-result.txt', 'w', encoding='utf-8').write('\n'.join(out))