Skip to content

Piped communication on Windows #6180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 23, 2021
Merged
21 changes: 14 additions & 7 deletions src/util/piped_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@

# define BUFSIZE 2048

#ifdef _WIN32
std::wstring process_windows_args(const std::vector<std::string> commandvec)
{
std::wstring result = widen(commandvec[0]);
for(int i = 1; i < commandvec.size(); i++)
{
result.append(L" ");
result.append(quote_windows_arg(widen(commandvec[i])));
}
return result;
}
#endif

piped_processt::piped_processt(const std::vector<std::string> commandvec)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognise this was here before, but any insight as to why this isn't being passed as a reference? The const doesn't seem terribly useful at present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No insight, but fixed now.

{
// Default state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to split up this mega-function a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split out a small helper function, but the function is pretty straightforward, just many lines due to many arguments to function calls to create Windows processes/pipes (also lots of commends/explanation).

Expand Down Expand Up @@ -193,13 +206,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
start_info.hStdOutput = child_std_OUT_Wr;
start_info.hStdInput = child_std_IN_Rd;
start_info.dwFlags |= STARTF_USESTDHANDLES;
// Unpack the command into a single string for Windows API
std::wstring cmdline = widen(commandvec[0]);
for(int i = 1; i < commandvec.size(); i++)
{
cmdline.append(L" ");
cmdline.append(quote_windows_arg(widen(commandvec[i])));
}
const std::wstring cmdline = process_windows_args(commandvec);
// Note that we do NOT free this since it becomes part of the child
// and causes heap corruption in Windows if we free!
const BOOL success = CreateProcessW(
Expand Down