Skip to content

Commit 8510283

Browse files
committed
Split out helper function for Windows string construction
Split out a helper function to process an array of strings into a single wide string for use in Windows commands.
1 parent c62310f commit 8510283

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/util/piped_process.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,19 @@
101101

102102
# define BUFSIZE 2048
103103

104+
#ifdef _WIN32
105+
std::wstring process_windows_args(const std::vector<std::string> commandvec)
106+
{
107+
std::wstring result = widen(commandvec[0]);
108+
for(int i = 1; i < commandvec.size(); i++)
109+
{
110+
result.append(L" ");
111+
result.append(quote_windows_arg(widen(commandvec[i])));
112+
}
113+
return result;
114+
}
115+
#endif
116+
104117
piped_processt::piped_processt(const std::vector<std::string> commandvec)
105118
{
106119
// Default state
@@ -193,13 +206,7 @@ piped_processt::piped_processt(const std::vector<std::string> commandvec)
193206
start_info.hStdOutput = child_std_OUT_Wr;
194207
start_info.hStdInput = child_std_IN_Rd;
195208
start_info.dwFlags |= STARTF_USESTDHANDLES;
196-
// Unpack the command into a single string for Windows API
197-
std::wstring cmdline = widen(commandvec[0]);
198-
for(int i = 1; i < commandvec.size(); i++)
199-
{
200-
cmdline.append(L" ");
201-
cmdline.append(quote_windows_arg(widen(commandvec[i])));
202-
}
209+
const std::wstring cmdline = process_windows_args(commandvec);
203210
// Note that we do NOT free this since it becomes part of the child
204211
// and causes heap corruption in Windows if we free!
205212
const BOOL success = CreateProcessW(

0 commit comments

Comments
 (0)