Created
July 25, 2024 01:31
-
-
Save anton-matosov/805a4832a1ba27d84306708fd35b31a9 to your computer and use it in GitHub Desktop.
Cross platform environment variable inspector (tested on macOS Sonoma 14.5 and python 3.12)
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
#!/usr/bin/env python | |
import psutil | |
import sys | |
if len(sys.argv) >= 2: | |
pid = int(sys.argv[1]) | |
else: | |
import questionary | |
answer = questionary.select( | |
"Which process to inspect?", | |
choices=[ | |
f'{proc.name()} | {proc.pid}' for proc in psutil.process_iter(["pid", "name"]) | |
]).ask() # returns value of selection | |
pid = int(answer.split(" | ")[1]) | |
proc = psutil.Process(pid) | |
env = proc.environ() | |
for key, value in env.items(): | |
print(f"{key}={value}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment