| 1640 | |
| 1641 | |
| 1642 | inline void Popen::execute_process() noexcept(false) |
| 1643 | { |
| 1644 | #ifdef __USING_WINDOWS__ |
| 1645 | if (this->shell_) { |
| 1646 | throw OSError("shell not currently supported on windows", 0); |
| 1647 | } |
| 1648 | |
| 1649 | void* environment_string_table_ptr = nullptr; |
| 1650 | env_vector_t environment_string_vector; |
| 1651 | if(this->env_.size()){ |
| 1652 | environment_string_vector = util::CreateUpdatedWindowsEnvironmentVector(env_); |
| 1653 | environment_string_table_ptr = (void*)environment_string_vector.data(); |
| 1654 | } |
| 1655 | |
| 1656 | if (exe_name_.length()) { |
| 1657 | this->vargs_.insert(this->vargs_.begin(), this->exe_name_); |
| 1658 | this->populate_c_argv(); |
| 1659 | } |
| 1660 | this->exe_name_ = vargs_[0]; |
| 1661 | |
| 1662 | std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; |
| 1663 | std::wstring argument; |
| 1664 | std::wstring command_line; |
| 1665 | bool first_arg = true; |
| 1666 | |
| 1667 | for (auto arg : this->vargs_) { |
| 1668 | if (!first_arg) { |
| 1669 | command_line += L" "; |
| 1670 | } else { |
| 1671 | first_arg = false; |
| 1672 | } |
| 1673 | argument = converter.from_bytes(arg); |
| 1674 | util::quote_argument(argument, command_line, false); |
| 1675 | } |
| 1676 | |
| 1677 | // CreateProcessW can modify szCmdLine so we allocate needed memory |
| 1678 | wchar_t *szCmdline = new wchar_t[command_line.size() + 1]; |
| 1679 | wcscpy_s(szCmdline, command_line.size() + 1, command_line.c_str()); |
| 1680 | PROCESS_INFORMATION piProcInfo; |
| 1681 | STARTUPINFOW siStartInfo; |
| 1682 | BOOL bSuccess = FALSE; |
| 1683 | DWORD creation_flags = CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW; |
| 1684 | |
| 1685 | // Set up members of the PROCESS_INFORMATION structure. |
| 1686 | ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION)); |
| 1687 | |
| 1688 | // Set up members of the STARTUPINFOW structure. |
| 1689 | // This structure specifies the STDIN and STDOUT handles for redirection. |
| 1690 | |
| 1691 | ZeroMemory(&siStartInfo, sizeof(STARTUPINFOW)); |
| 1692 | siStartInfo.cb = sizeof(STARTUPINFOW); |
| 1693 | |
| 1694 | siStartInfo.hStdError = this->stream_.g_hChildStd_ERR_Wr; |
| 1695 | siStartInfo.hStdOutput = this->stream_.g_hChildStd_OUT_Wr; |
| 1696 | siStartInfo.hStdInput = this->stream_.g_hChildStd_IN_Rd; |
| 1697 | |
| 1698 | siStartInfo.dwFlags |= STARTF_USESTDHANDLES; |
| 1699 |
nothing calls this directly
no test coverage detected