[Boost-bugs] [Boost C++ Libraries] #13333: Child processes started with boost::process have incorrect argv if executable path contains spaces

Subject: [Boost-bugs] [Boost C++ Libraries] #13333: Child processes started with boost::process have incorrect argv if executable path contains spaces
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-12-08 16:54:21


#13333: Child processes started with boost::process have incorrect argv if
executable path contains spaces
-------------------------------------------------+-------------------------
 Reporter: Jonathan Jaloszynski | Owner: (none)
  <Jon_Jaloszynski@…> |
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: process
  Version: Boost 1.65.0 | Severity: Problem
 Keywords: |
-------------------------------------------------+-------------------------
 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.

 To demonstrate this problem, the following program dumps argv:

 {{{

 #include <iostream>
 int main(int argc, char* argv[])
 {
         // Dump the command line arguments.
         std::cout << argc << std::endl;
         for (int i = 0; i < argc; ++i)
                 std::cout << argv[i] << std::endl;
         return 0;
 }

 }}}

 Compile this and place the resulting DumpCmdLine.exe in "c:\dir with
 space\" and "c:\dirwithoutspace\".

 The following program runs this executable using boost::process, and
 demonstrates the problem:

 {{{
 #include "stdafx.h"
 #include <boost/process.hpp>
 #include <boost/filesystem.hpp>

 int main()
 {
         boost::filesystem::path toRun{ "c:\\dir with
 space\\DumpCmdLine.exe" };
         auto child = boost::process::child(toRun, L"realArgument");
         child.wait();
     return 0;
 }

 }}}

 The child process argv contains 4 elements, "c:\dir", "with",
 "space\DumpCmdLine.exe", and "realArgument".

 When there is no space in the executable path, the child process argv
 contains 2 elements: "c:\dirwithoutspace\DumpCmdLine.exe", and
 "realArgument".

 When DumpCmdLine.exe is called from the command line, it receives the same
 2 arguments. The command line I used is:
 {{{
 "c:\dir with space\DumpCmdLine.exe" realArgument
 }}}

 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.

-- 
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13333>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-12-08 17:00:50 UTC