Last active
December 14, 2018 06:04
-
-
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. :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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