Is there a way to view the environment variables of a specific process. I know that i can see them using the Process Explorer. However, i need to use them in a batch or powershell script. Is there a command that does that. Can I use the procexp.exe of the Process explorer to get this information to use it in a following script?
For Windows, this is messy but not complicated using Python
psutil.Process.environ() library function.
In one terminal
$ $ENV:test = 'abc' $ $PID 108444
$ python -c 'import psutil; print(psutil.Process(pid=108444).environ()["TEST"])' abc
(Notice the variable names are capitalized in Windows.)
I tested this in macOS and linux (RHEL8), and it doesn't work. This
psutil functionality works real-time in Windows, but it's not guaranteed for all OS. The documentation says this:
Note: this might not reflect changes made after the process started.