如何使用 python 从应用程序读取输出

How to read output from an application using python

目前正在尝试记录传出 TCP 连接的列表,然后将当前列表与之前的列表进行比较,以查看已建立的连接。然而,TCPView.exe 似乎并不走运。我可以 运行 这个应用程序:

def get_tcp_conns():
    process = Popen([r"C:\Users\PC\Downloads\TCPView\Tcpview.exe"], stdout=PIPE, shell=True)
    for line in io.TextIOWrapper(proc.stdout, encoding="utf-8"):
        print(line)  # Do whatever here

但是,这不会返回任何文本。不确定该去哪里,因为我不知道如何读取 python

中的 TCP 信息

应该是这样的

import subprocess 

def get_tcp_conns():
    process = subprocess.run("C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe './C:Users/PC/Downloads/TCPView/Tcpview.exe' ", shell=True, capture_output=True)
    print(process.stdout)