| 1077 | } |
| 1078 | |
| 1079 | inline void Popen::execute_process() noexcept(false) |
| 1080 | { |
| 1081 | #ifdef WIN32 |
| 1082 | if (exe_name_.length()) { |
| 1083 | this->vargs_.insert(this->vargs_.begin(), this->exe_name_); |
| 1084 | this->populate_c_argv(); |
| 1085 | } |
| 1086 | this->exe_name_ = vargs_[0]; |
| 1087 | |
| 1088 | std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; |
| 1089 | std::wstring argument; |
| 1090 | std::wstring command_line; |
| 1091 | bool first_arg = true; |
| 1092 | |
| 1093 | for (auto arg : this->vargs_) { |
| 1094 | if (!first_arg) { |
| 1095 | command_line += L" "; |
| 1096 | } else { |
| 1097 | first_arg = false; |
| 1098 | } |
| 1099 | argument = converter.from_bytes(arg); |
| 1100 | util::quote_argument(argument, command_line, false); |
| 1101 | } |
| 1102 | |
| 1103 | // CreateProcessW can modify szCmdLine so we allocate needed memory |
| 1104 | wchar_t *szCmdline = new wchar_t[command_line.size() + 1]; |
| 1105 | wcscpy_s(szCmdline, command_line.size() + 1, command_line.c_str()); |
| 1106 | PROCESS_INFORMATION piProcInfo; |
| 1107 | STARTUPINFOW siStartInfo; |
| 1108 | BOOL bSuccess = FALSE; |
| 1109 | DWORD creation_flags = CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW; |
| 1110 | |
| 1111 | // Set up members of the PROCESS_INFORMATION structure. |
| 1112 | ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION)); |
| 1113 | |
| 1114 | // Set up members of the STARTUPINFOW structure. |
| 1115 | // This structure specifies the STDIN and STDOUT handles for redirection. |
| 1116 | |
| 1117 | ZeroMemory(&siStartInfo, sizeof(STARTUPINFOW)); |
| 1118 | siStartInfo.cb = sizeof(STARTUPINFOW); |
| 1119 | |
| 1120 | siStartInfo.hStdError = this->stream_.g_hChildStd_ERR_Wr; |
| 1121 | siStartInfo.hStdOutput = this->stream_.g_hChildStd_OUT_Wr; |
| 1122 | siStartInfo.hStdInput = this->stream_.g_hChildStd_IN_Rd; |
| 1123 | |
| 1124 | siStartInfo.dwFlags |= STARTF_USESTDHANDLES; |
| 1125 | |
| 1126 | // Create the child process. |
| 1127 | bSuccess = CreateProcessW(NULL, |
| 1128 | szCmdline, // command line |
| 1129 | NULL, // process security attributes |
| 1130 | NULL, // primary thread security attributes |
| 1131 | TRUE, // handles are inherited |
| 1132 | creation_flags, // creation flags |
| 1133 | NULL, // use parent's environment |
| 1134 | NULL, // use parent's current directory |
| 1135 | &siStartInfo, // STARTUPINFOW pointer |
| 1136 | &piProcInfo); // receives PROCESS_INFORMATION |
nothing calls this directly
no test coverage detected