Determining running programs in Python

前端 未结 4 476
深忆病人
深忆病人 2020-11-30 08:48

How would I use Python to determine what programs are currently running. I am on Windows.

4条回答
  •  难免孤独
    2020-11-30 09:16

    import os
    os.system('WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid')
    f = open("C:\ProcessList.txt")
    plist = f.readlines()
    f.close()
    

    Now plist contains a formatted whitespace-separated list of processes:

    • The first column is the name of the executable that is running
    • The second column is the command that represents the running process
    • The third column is the process ID

    This should be simple to parse with python. Note that the first row of data are labels for the columns, and not actual processes.

    Note that this method only works on windows!

提交回复
热议问题