c++ execute command and get working directory : I want to execute a shell command in c++ and at the end I would like to fetch the current working directory of the executed process.
e.g. I executing the command `cd C:\`
then at the end of the command I want to get the directory `C:\`
and store it in a variable.

What I tried was [`pipe = _popen(cmd, "r")`][1] to execute the command, but at the end of the command, even when [`_pclose(pipe)`][2] wasn't called yet, when I called [`_getcwd(NULL, 0)`][3], I got the cwd of the running c++ program and not the changed cwd from `_popen`.

does anyone know, how I could achieve this?


  [1]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/popen-wpopen
  [2]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/pclose
  [3]: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getcwd-wgetcwd