python - 如何使用 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)
推荐阅读
- asp.net-mvc - 如何使用 ASP.Net MVC 4.5 创建多登录用户
- r - 使用 dplyr 时,我应该在哪一步将数据发送到 data.table() 以获得最佳性能?
- angular - 使用 Angular 6 的异步 API 请求
- google-api - Google Search Console - 获取属性集名称
- c# - 在 line player.PlaySync() 中出现错误
- javascript - Node.js 在不打印换行符的情况下获取用户输入
- javascript - 目标完成和事件总数之间的差异 - 服务器端跟踪 Google Analytics
- python - 使用另一个类中的函数调用一个类中的函数
- asp.net - 从命令行更新 Css/Js 包(Visual Studio Bundler Minifier)
- hyperhtml - How do you get around Cloned Templates losing Element References?