'why run program with boost::process::spawn with modifed PATH environment failed?
the code as follow:
#include <boost/process.hpp>
#include <iostream>
int main()
{
// cmd
// std::string cmd{"g++.exe"}; // ok
std::string cmd{"wx.exe"}; // not work
std::string cmd_path{"E:\\app\\lang\\C\\exe\\examples\\libraries\\wx\\build_CodeBlocks"};
// env
boost::process::environment env{boost::this_process::environment()};
env["PATH"] += cmd_path;
std::cout << env["PATH"].to_string() << std::endl;
// run
// boost::process::spawn(cmd, env);
// boost::process::spawn(cmd_path + "/" + cmd, env);
boost::filesystem::path p = boost::process::search_path(cmd);
if (boost::filesystem::exists(p))
{
std::cout << p << std::endl;
}
else
{
std::cout << cmd << " does not exists!" << std::endl;
return -1;
}
boost::process::spawn(p, env);
return 0;
}
i think my code is same as the example in here(the bottom of that page), but it doesn't work.
the modifed PATH as follow:
C:\Users\Administrator\bin;E:\app\git\PortableGit\mingw32\bin;E:\app\git\PortableGit\usr\local\bin;E:\app\git\PortableGit\usr\bin;E:\app\git\PortableGit\usr\bin;E:\app\git\PortableGit\mingw32\bin;E:\app\git\PortableGit\usr\bin;C:\Users\Administrator\bin;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;E:\app\git\PortableGit\usr\bin\vendor_perl;E:\app\git\PortableGit\usr\bin\core_perl;E:/app/lang/C/exe/examples/libraries/wx/build_CodeBlocks
the cmd_path is appended at the end.
the error message as follow:
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. terminate called after throwing an instance of 'boost::process::process_error' what(): CreateProcess failed: No such device or address
why?
when cmd is g++, which is in the old unmodified PATH, it works.
can anyone help?
conclusion: the spawned process did not search the updated PATH environment.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|