| 1165 | } |
| 1166 | |
| 1167 | int32 WindowsPlatform::CreateProcess(CreateProcessSettings& settings) |
| 1168 | { |
| 1169 | LOG(Info, "Command: {0} {1}", settings.FileName, settings.Arguments); |
| 1170 | if (settings.WorkingDirectory.HasChars()) |
| 1171 | { |
| 1172 | LOG(Info, "Working directory: {0}", settings.WorkingDirectory); |
| 1173 | } |
| 1174 | const bool captureStdOut = settings.LogOutput || settings.SaveOutput; |
| 1175 | |
| 1176 | int32 result = 0; |
| 1177 | if (settings.ShellExecute) |
| 1178 | { |
| 1179 | SHELLEXECUTEINFOW shExecInfo = { 0 }; |
| 1180 | shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); |
| 1181 | shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; |
| 1182 | shExecInfo.lpFile = settings.FileName.GetText(); |
| 1183 | shExecInfo.lpParameters = settings.Arguments.HasChars() ? settings.Arguments.Get() : nullptr; |
| 1184 | shExecInfo.lpDirectory = settings.WorkingDirectory.HasChars() ? settings.WorkingDirectory.Get() : nullptr; |
| 1185 | shExecInfo.nShow = settings.HiddenWindow ? SW_HIDE : SW_SHOW; |
| 1186 | if (ShellExecuteExW(&shExecInfo) == FALSE) |
| 1187 | { |
| 1188 | result = 1; |
| 1189 | LOG(Warning, "Cannot start process. Error code: 0x{0:x}", (uint64)GetLastError()); |
| 1190 | } |
| 1191 | else if (settings.WaitForEnd) |
| 1192 | { |
| 1193 | WaitForSingleObject(shExecInfo.hProcess, INFINITE); |
| 1194 | DWORD exitCode; |
| 1195 | if (GetExitCodeProcess(shExecInfo.hProcess, &exitCode) != 0) |
| 1196 | result = exitCode; |
| 1197 | CloseHandle(shExecInfo.hProcess); |
| 1198 | } |
| 1199 | } |
| 1200 | else |
| 1201 | { |
| 1202 | result = -1; |
| 1203 | const String cmdLine = settings.FileName + TEXT(" ") + settings.Arguments; |
| 1204 | |
| 1205 | STARTUPINFOEX startupInfoEx; |
| 1206 | ZeroMemory(&startupInfoEx, sizeof(startupInfoEx)); |
| 1207 | startupInfoEx.StartupInfo.cb = sizeof(startupInfoEx); |
| 1208 | if (settings.HiddenWindow) |
| 1209 | { |
| 1210 | startupInfoEx.StartupInfo.dwFlags |= STARTF_USESHOWWINDOW; |
| 1211 | startupInfoEx.StartupInfo.wShowWindow |= SW_HIDE | SW_SHOWNOACTIVATE; |
| 1212 | } |
| 1213 | |
| 1214 | DWORD dwCreationFlags = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS; |
| 1215 | if (settings.HiddenWindow) |
| 1216 | dwCreationFlags |= CREATE_NO_WINDOW; |
| 1217 | |
| 1218 | Char* environmentStr = nullptr; |
| 1219 | if (settings.Environment.HasItems()) |
| 1220 | { |
| 1221 | dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT; |
| 1222 | |
| 1223 | int32 totalLength = 1; |
| 1224 | for (auto& e : settings.Environment) |