| 36 | } |
| 37 | |
| 38 | void Process::Run(const std::wstring& pathName, const std::wstring& args) |
| 39 | { |
| 40 | auto pos = pathName.find_last_of(L"\\/:"); |
| 41 | m_name = pos != pathName.npos ? pathName.substr(pos + 1) : pathName; |
| 42 | |
| 43 | std::wstring commandLine; |
| 44 | commandLine += L"\""; |
| 45 | commandLine += pathName; |
| 46 | commandLine += L"\""; |
| 47 | |
| 48 | if (!args.empty()) |
| 49 | { |
| 50 | commandLine += L" "; |
| 51 | commandLine += args; |
| 52 | } |
| 53 | |
| 54 | SECURITY_ATTRIBUTES saAttr; |
| 55 | saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); |
| 56 | saAttr.bInheritHandle = true; |
| 57 | saAttr.lpSecurityDescriptor = nullptr; |
| 58 | |
| 59 | HANDLE stdInRd, stdInWr; |
| 60 | if (!CreatePipe(&stdInRd, &stdInWr, &saAttr, 0)) |
| 61 | ThrowLastError("CreatePipe"); |
| 62 | Handle stdInRd2(stdInRd); |
| 63 | m_stdIn.reset(stdInWr); |
| 64 | if (!SetHandleInformation(stdInWr, HANDLE_FLAG_INHERIT, 0)) |
| 65 | ThrowLastError("SetHandleInformation"); |
| 66 | |
| 67 | HANDLE stdOutRd, stdOutWr; |
| 68 | if (!CreatePipe(&stdOutRd, &stdOutWr, &saAttr, 0)) |
| 69 | ThrowLastError("CreatePipe"); |
| 70 | Handle stdOutWr2(stdOutWr); |
| 71 | m_stdOut.reset(stdOutRd); |
| 72 | if (!SetHandleInformation(stdOutRd, HANDLE_FLAG_INHERIT, 0)) |
| 73 | ThrowLastError("SetHandleInformation"); |
| 74 | |
| 75 | HANDLE stdErrRd, stdErrWr; |
| 76 | if (!CreatePipe(&stdErrRd, &stdErrWr, &saAttr, 0)) |
| 77 | ThrowLastError("CreatePipe"); |
| 78 | Handle stdErrWr2(stdErrWr); |
| 79 | m_stdErr.reset(stdErrRd); |
| 80 | if (!SetHandleInformation(stdErrRd, HANDLE_FLAG_INHERIT, 0)) |
| 81 | ThrowLastError("SetHandleInformation"); |
| 82 | |
| 83 | STARTUPINFO startupInfo; |
| 84 | startupInfo.cb = sizeof(startupInfo); |
| 85 | startupInfo.lpReserved = nullptr; |
| 86 | startupInfo.lpDesktop = nullptr; |
| 87 | startupInfo.lpTitle = nullptr; |
| 88 | startupInfo.dwX = 0; |
| 89 | startupInfo.dwY = 0; |
| 90 | startupInfo.dwXSize = 0; |
| 91 | startupInfo.dwYSize = 0; |
| 92 | startupInfo.dwXCountChars = 0; |
| 93 | startupInfo.dwYCountChars = 0; |
| 94 | startupInfo.dwFillAttribute = 0; |
| 95 | startupInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; |
nothing calls this directly
no test coverage detected