How to deal with spaces in path using boost::process::child?

boost::process::child example
boost/process/child environment
boost::process::child arguments
boost/process tutorial
boost::process::system
boost/process context
boost/process/group
boost/process hpp

I need to execute a Windows Batch script. By company policy, I have to use boost::process::child for that matter. The path to the Windows Batch script contains whitespaces (e.g. C:\Foo Bar\batch.bat).

I am using the following code:

namespace bp = boost::process;
error_code errorCode;
bp::ipstream errorStream;
auto child = bp::child("C:\\Foo Bar\\batch.bat",
    errorCode,
    bp::std_out > bp::null,    // ignore standard output
    bp::std_err > errorStream, // capture standard error
    bp::windows::hide,        // hide window
    bp::shell);               // use shell

  vector<string> errorData;
  string errorLine;

  while (child.running() && getline(errorStream, errorLine) && !errorLine.empty())
  {
    errorData.push_back(errorLine);
  }
  child.wait();

The issue is that the system (boost::process) does not found the path. A error message would look like:

'C:\Foo' is not recognized as an internal or external command, operable program or batch file.

I also have tried the following masking variants:

  • C:\\Foo Bar\\batch.bat
  • C:\\Foo\ Bar\\batch.bat
  • "C:\\Foo Bar\\batch.bat"
  • C:\\Foo~1\\batch.bat

How to mask the whitespace correctly, so child() can find/execute the Batch script correctly?

Wrap "C:\\Foo Bar\\batch.bat" into boost::filesystem::path(), so that it quotes the string for you:

auto child = bp::child(boost::filesystem::path("C:\\Foo Bar\\batch.bat"),

Tutorial - 1.64.0, namespace bp = boost::process; //we will assume this for all further examples string from an external source as boost::filesystem::path , we can do this too. a process and immediately detaches it, so no handle will be returned and the process will be ignored. So we launch the process, by calling the child constructor. Therefore, you can process a large amount of data without using too much memory at any one time. Let’s see how we can use spawn() to make a child process. We will write a new Node.js module that creates a child process to run the find command. We will use the find command to list all the files in the current directory.

I suggest following @Maxim's answer.

Alternatively, escape the space using a backslash:

"C:\\Foo\\ Bar\\batch.bat"

Bug, Hi, thanks for the cool library, I'm enjoying using it and look forward to its to host and review code, manage projects, and build software together. It's possible that this isn't a Clara bug per se, but just that boost::path don't� We did not include all the necessary header files, only those dealing with property tree. First, we create an empty ptree and populate it using function read_xml. It is defined in namespace boost::property_tree, but due to argument dependent look-up it can be used without any namespace qualification.

bp::child c(
    bp::exe(boost::filesystem::path("C:\\Foo Bar\\batch.bat").c_str()),
    bp::cmd("options here"), 
    bp::environment(env),       
    bp::std_in.close(),
    bp::std_out > os,
    bp::std_err > es,
    bp::start_dir("workdir here")
);

[boost] [gsoc] Boost.Process done, Google Summer of Code program: We have a complete library to manage system processes now The code to start child processes on POSIX platforms has been carefully using boost::process::launch_pipeline() there is nothing in this Boost. Process pistream/postream do not inherit from std::istream/std::ostream nor to In a number path game, numbers are evenly spaced along a path that moves from smaller to larger numbers (e.g., 1 to 5). Children move along the number path—and practice several math concepts—by rolling a die or using a spinner. While playing number path games, children practice these early math concepts:

Assuming this gets turned into a Windows CreateProcess call, then the path to the application must be in double quotes in order to allow spaces in the path. In fact it's recommended that the path ALWAYS be surrounded in double quotes.

So you would use:

auto child = bp::child("\"C:\\Foo Bar\\batch.bat\"",

I don't know if Boost::child will actually allow this to work.

7 Ways to Foster Creativity in Your Kids, Many people assume that creativity is an inborn talent that their kids deal with change—as well as take advantage of new opportunities. In addition to creative spaces, you need to foster a creative atmosphere. The focus of creative activities should be on process: generating (vs. evaluating) new ideas� cd path\to\some\directory. followed by Return. For example, cd C:\Program Files\boost\boost_1_62_0. Long commands can be continued across several lines by typing a caret (^) at the end of all but the last line. Some examples on this page use that technique to save horizontal space.

Children's Spaces, From the beginning, we reach out, we crawl, we balance across objects in our play strategies because other children can easily enter the climbing route at any This process is a form of mental flexibility, however physical flexibility is also stretch beyond their known capabilities, they develop and improve their skills. On a Windows machine, the path can be found by right-clicking the file icon, and selecting "Properties." You'll see the file path, minus the name of the file, in the "General" tab, labeled "location." The full file name will be this path plus the name of the file (make sure to include the ".csv" at the end).

GNU make, 4.5.1 VPATH : Search Path for All Prerequisites; 4.5.2 The vpath Implicit Rules, Use implicit rules to treat many files alike, based on Simply by being mentioned as a target, this tells make to export all variables to child processes by default. Double-colon rules are explicit rules written with ' :: ' instead of� The issue is with space " " in the subsystem executable path (ProgramFiles). I checked the code and the current implementation does not support it. As a work around, you could create a symlink (with no spaces in its path) the following way and specify the link in the subsystem path

State of the World's Children 2012: Children in an Urban World, Children in an Urban World United Nations Children's Fund (UNICEF) understand how its problems are related to the streets, paths and other routes In each case, care is taken to minimize the disruption caused by the construction process. Girls and boys of different ages use urban space in diverse ways, respond to it�

Comments
  • Perhaps adding quotes would help? "\"C:\\Foo Bar\\batch.bat\""
  • I would additionally suggest trying one or all of the following: "C:\\Foo\ Bar\\batch.bat", "C:\\Foo\" \"Bar\\batch.bat", "C:/Foo Bar/batch.bat" and "\"C:/Foo Bar/batch.bat\"".
  • Unfortunately, this solution will result in the same error as mentioned in the question. Unless I overlook something obvious.
  • I can confirm this does not work (boost 1.64.0). Having the same problem and no idea how to solve it.
  • I'm assuming, how it currently reads, that it would look for "C:\Foo\ Bar\batch.bat". My understanding is that the backslashes in the path are each escaped, using a backslash as the escape character, so it would follow that the space is escaped similarly. I would therefore expect that you should use "C:\\Foo\ Bar\\batch.bat" instead. That said, burnersk states in the question, that they've already tried that particular string, (but without the doublequotes).
  • The second backslash is the C/C++ string literal escape, so my string would be compiled to the actual characters/bytes C:\Foo\Bar\ Bar\batch.bat.
  • ruben, I'm not sure if I understand, if those are the actual characters, they don't match C:\Foo Bar\batch.bat.
  • If you pass that to e.g. cmd the espaced space will turn into a space. But in any case it seems extremely odd to me that @Maxim's suggestion doesn't work. I can4t be bothered to try and reproduce though.
  • Welcome to stackoverflow. When answering questions, please explain why your code solves the OP's question. For more info, check here How to Answer