aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
69 stars 17 forks source link

Get the current process data like in Process class for subprocesses #16

Open kabukunz opened 3 years ago

kabukunz commented 3 years ago

Actually it seems we can start a subprocess with Process class; but is there a way to get the current process data? I'd like to read its env vars and get the running process name... Thank you

aslze commented 3 years ago

Current functionality allows reading/writing the subprocess' stdout/stderr/stdin as it runs. The process name is the name of the executable you run, isn't it? And reading its environment variables. Not sure if that is even possible on Windows. I'll check the docs and add that if it is possible. A subprocess inherits the parent process env vars. If it sets new env vars it could communicate them to the parent via stdout or somewhere else. I'll see if that can be "spied" from the parent.

aslze commented 3 years ago

On Linux you can read some process's environment vars from /proc/<PID>/environ. But I can't find similar functionality on the Windows API. Do you know a way?

kabukunz commented 3 years ago

Stackoverflow points to a way using some command line trick:

https://superuser.com/questions/415360/how-do-i-find-out-command-line-arguments-of-a-running-program

while it seems the canonical way is by using win openprocess thru C:

https://stackoverflow.com/questions/4570174/how-to-get-the-process-name-in-c

But bear with me, I'm no windows expert al all...