Boost C++ Libraries: Ticket #13333: Child processes started with boost::process have incorrect argv if executable path contains spaces https://svn.boost.org/trac10/ticket/13333 <p> If an executable to start has spaces in its path, the process started with either boost::process::child or boost::process::system will have a strange argv. Specifically, the segments of the executable's path will be individual elements in the argv array. </p> <p> To demonstrate this problem, the following program dumps argv: </p> <pre class="wiki"> #include &lt;iostream&gt; int main(int argc, char* argv[]) { // Dump the command line arguments. std::cout &lt;&lt; argc &lt;&lt; std::endl; for (int i = 0; i &lt; argc; ++i) std::cout &lt;&lt; argv[i] &lt;&lt; std::endl; return 0; } </pre><p> Compile this and place the resulting <a class="missing wiki">DumpCmdLine</a>.exe in "c:\dir with space\" and "c:\dirwithoutspace\". </p> <p> The following program runs this executable using boost::process, and demonstrates the problem: </p> <pre class="wiki">#include "stdafx.h" #include &lt;boost/process.hpp&gt; #include &lt;boost/filesystem.hpp&gt; int main() { boost::filesystem::path toRun{ "c:\\dir with space\\DumpCmdLine.exe" }; auto child = boost::process::child(toRun, L"realArgument"); child.wait(); return 0; } </pre><p> The child process argv contains 4 elements, "c:\dir", "with", "space\<a class="missing wiki">DumpCmdLine</a>.exe", and "realArgument". </p> <p> When there is no space in the executable path, the child process argv contains 2 elements: "c:\dirwithoutspace\<a class="missing wiki">DumpCmdLine</a>.exe", and "realArgument". </p> <p> When <a class="missing wiki">DumpCmdLine</a>.exe is called from the command line, it receives the same 2 arguments. The command line I used is: </p> <pre class="wiki">"c:\dir with space\DumpCmdLine.exe" realArgument </pre><p> This was observed on a Windows 10 system, 64 bit build both debug and release configurations. Visual Studio 2017 (15.4.3) was used to build. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13333 Trac 1.4.3 Jonathan Jaloszynski <Jon_Jaloszynski@…> Fri, 08 Dec 2017 18:46:49 GMT <link>https://svn.boost.org/trac10/ticket/13333#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13333#comment:1</guid> <description> <p> When using the "command style" of execution with a quoted executable path, the expected (2 argument) argv is received by the child process. This is a bit of a hack since quoting the path is likely OS specific. </p> <pre class="wiki"> int main() { std::wstring cmdString = L"\"c:\\dir with space\\DumpCmdLine.exe\" realArgument"; auto child = boost::process::child(boost::process::cmd = cmdString); child.wait(); return 0; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 04 Mar 2018 19:24:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13333#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13333#comment:2</guid> <description> <p> Confirm this happens in my setup as well, Windows 10 x64, VS 2017, boost 1.65.1 </p> </description> <category>Ticket</category> </item> </channel> </rss>