Skip to content

Instantly share code, notes, and snippets.

@angeloped
Last active December 14, 2018 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeloped/1f54544c43b9cd6e6daff8da2064fdc7 to your computer and use it in GitHub Desktop.
Save angeloped/1f54544c43b9cd6e6daff8da2064fdc7 to your computer and use it in GitHub Desktop.
Tested and working on Linux and Windows. I added OSX, I think it'll work. :)
import os, sys
"""
Author: https://github.com/angeloped
Do anything you want with this code.
"""
# determine operating system
os_type = sys.platform.lower()
# determine command to be executed
if "linux" in os_type:
command="ps ax"
elif "windows" in os_type:
command="tasklist"
elif "darwin" in os_type:
command="ps ax"
# execute command via pipe
pipe_output = os.popen(command).read().split("\n")
# delete separators
if "windows" in os_type:
del pipe_output[1]
# split whitespaces/tabs delimiters
processes = [pse.split() for pse in pipe_output if not pse == ""]
print(processes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment