arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
449 stars 90 forks source link

Windows support for environment variables #61

Closed deanmsands3 closed 3 years ago

deanmsands3 commented 3 years ago

In the Windows sp::Popen, we have this:

  // Create the child process.
  bSuccess = CreateProcessW(NULL,
                            szCmdline,    // command line
                            NULL,         // process security attributes
                            NULL,         // primary thread security attributes
                            TRUE,         // handles are inherited
                            0,            // creation flags
                            NULL,         // use parent's environment
                            NULL,         // use parent's current directory
                            &siStartInfo, // STARTUPINFOW pointer
                            &piProcInfo); // receives PROCESS_INFORMATION

which "uses parent's environment" i.e. no custom environment variable support.

I'll work on a pull-request to get the functionality on par with *nix.

deanmsands3 commented 3 years ago

I wrote up a gist covering the basic idea of creating a child process with a modified environment. One of the speed-bumps is that Windows uses wide characters.

deanmsands3 commented 3 years ago

Thanks, @arun11299 !