使用 boost 启动进程时设置工作目录

Set the working directory when starting a process with boost

我正在寻找一种在使用 boost::process::systemboost::process::child 启动进程时指定工作目录的方法。文档 https://www.boost.org/doc/libs/1_77_0/doc/html/boost_process/tutorial.html 中有一些有用的示例,但与我感兴趣的主题无关。

child 构造函数如下所示:

template<typename ...Args>
child::child(Args&&...args)

而且我还没有找到涵盖 Args 可能是什么的完整文档,只有一些不完整的示例。

#include <boost/process/start_dir.hpp>

namespace bp = boost::process;

int result = bp::system("/usr/bin/g++", "main.cpp", bp::start_dir("/home/user"));

bp::child c(bp::search_path("g++"), "main.cpp", bp::start_dir("/home/user"));
c.wait();

boost::process::start_dir and the complete Reference

Args 是程序名称、程序参数和参考中的其他进程属性。