[common] Add a way to set the process startup directory (#63)

This will be needed later for switching to sftp, since calling lcd in
sftp is tricky to get right (e.g. may or may not require /cygwin/c on
Windows, depending on whether sftp is native or not).
This commit is contained in:
Lutz Justen
2023-01-16 12:26:45 +01:00
committed by GitHub
parent 42f5ee9b44
commit f2177969fe
3 changed files with 24 additions and 2 deletions
+5 -2
View File
@@ -719,6 +719,10 @@ absl::Status WinProcess::Start() {
Util::GetLastWin32Error());
}
std::wstring startup_dir = Util::Utf8ToWideStr(start_info_.startup_dir);
const wchar_t* startup_dir_cstr =
!startup_dir.empty() ? startup_dir.c_str() : nullptr;
// Start the child process.
success = CreateProcess(NULL, // No module name (use command line)
command_cstr,
@@ -727,8 +731,7 @@ absl::Status WinProcess::Start() {
TRUE, // Inherit handles
ToCreationFlags(start_info_.flags),
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, &process_info_->pi);
startup_dir_cstr, &si, &process_info_->pi);
if (!success) {
return MakeStatus("CreateProcess() failed: %s", Util::GetLastWin32Error());