Skip to content

Instantly share code, notes, and snippets.

@dinya
Created December 4, 2017 11:01
Show Gist options
  • Select an option

  • Save dinya/739929f0386c313db433a0b5fb64c161 to your computer and use it in GitHub Desktop.

Select an option

Save dinya/739929f0386c313db433a0b5fb64c161 to your computer and use it in GitHub Desktop.
Get process list (name, pid) on win32 with python
import os
import re
def get_process_list_win32():
regexp = ur"^(?P<name>.*) \s+(?P<pid>\d+) [S|C].*$"
l = []
for i in os.popen('tasklist').readlines()[5:]:
g = re.search(regexp, i.decode("cp866").rstrip())
name = g.group("name").rstrip()
pid = g.group("pid")
l.append((name, pid))
return l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment