DLyons
DLyons

Reputation: 186

Boost "CreateProcess failed"

This is a "Hello World" test built in Visual Studio 2017 (v141). I suspect the problem is some 32-bit/64-bit mismatch, but I'm not sure how to check that.

I'm compiling the following as Debug x86 (it gives some warnings that I turn off with _SCL_SECURE_NO_WARNINGS but I think they aren't relevant and I also do a #define _WIN32_WINNT 0x0501). Attempting to compile as x64 throws TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified.

I'm linking to libboost_XXX-vc141-mt-1_64.lib libraries.

The actual code is

#include <iostream>
#include <boost/process.hpp>
#include <boost/process/windows.hpp>

namespace bp = boost::process;
int main(int argc, char * argv[])
{
    int result = bp::system("echo Hello");
}

which throws "Microsoft C++ exception: boost::process::process_error at memory location 0x0137EE34."

Upvotes: 1

Views: 1183

Answers (1)

sehe
sehe

Reputation: 393507

Apparently on windows, there's no concept of a default shell. You can explicitly invoke one:

int result = bp::system(bp::search_path("cmd.exe"), "/c", "echo Hello");

NOTE Optionally use %COMSPEC% to locate command shell

int result = bp::system(bp::search_path("cmd.exe"), "/c", "echo %COMSPEC%");

Upvotes: 1

Related Questions