How to read output from an application using python

混江龙づ霸主 提交于 2020-12-15 06:22:55

问题


Currently trying to record a list of outgoing TCP connections and then compare the present list to the previous list in order to see what connections have been established. However, TCPView.exe seems to be of no luck. I am able to run the application with this:

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

However, this is not returning any text. Not for sure where to go with this as I have no idea how to read the TCP information in python


回答1:


should be something like

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) 


来源:https://stackoverflow.com/questions/64638025/how-to-read-output-from-an-application-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!