See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

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

General Tech Bugs & Fixes

Max. 2000 characters



( 6 months ago )


I need to execute a Windows Batch script. By company policy, I have to use boost::process::childfor 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",
    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())

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?



( 6 months ago )

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"),

what's your interest