如何使用 boost::p rogram_options 解析本身包含开关的命令行参数
How can I parse command line arguments that themselves contain switches using boost::program_options?
我正在用C++编写一个程序,它是一些基准测试的包装器,开头包含一些设置代码,最后包含analisys代码。
我想并行运行最多两个基准测试。 这些的原始命令行是:
/path0/benchmark0 -switch0 -switch1 -switch2
/path1/benchmark1 -arg0 -arg1 -arg2 -arg4
我想把它们放在我的包装器的命令行上:
wrapper -setup_arg0 -setup_arg1 -analysis_arg0 --command0 /path0/benchmark0 -switch0 -switch1 -switch2 --command1 /path1/benchmark1 -arg0 -arg1 -arg2 -arg4
我想得到两个std::vector<std::string>
,command0
和command1
各一个,包含原始命令行。 这就是我的做法(使用 boost::program_options
):
("command0", po::value<std::vector< std::string> >(&command0)->multitoken(), "command line for thread 0")
("command1", po::value<std::vector< std::string> >(&command1)->multitoken(), "command line for thread 1")
这基本上有效。 但是,如果基准测试的参数以-
开头(就像我见过的大多数程序上的大多数开关一样),program_options
会尝试将它们解析为包装器开关的一部分,因为它不知道它们应该在 command0
或 command1
下分组在一起。
program_options
支持吗? 如果是这样,如何?
例:
在我工作的地方,有一个约定可以通过像这样"终止"多令牌来执行此操作:
wrapper <snip> --command0 /path0/benchmark0 -switch0 -switch1 -switch2 -command0-
(在此示例中,我以 -command0-
终止了--command0
。
我怎样才能program_options
这样处理它?
我认为最好将
调用命令的内容。
command0
和command1
的值作为单个字符串。 例如,
wrapper --command0 "/path0/benchmark0 ..." --command1 "/path1/benchmark1 ..."
是的,对于您来说,还有更多的工作要做,因为您必须wordexp
各自的命令字符串(除非您已经将这些字符串直接传递给 shell ;-)),但它更清楚地区分了包装器和
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 编译包含字符串的代码时遇到问题
- c++库的公共头文件中应该包含什么
- 将包含C样式数组的对象初始化为成员变量(C++)
- 既然存在危险,为什么项目要使用-I include开关
- 是否需要删除包含对象的"pair"?
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何将包含epoch时间的十六进制字符串转换为time_t
- 使用mongocxx驱动程序时包含头文件问题
- 如何在h文件中包含.o对象文件
- 在混合代码库中将C转换为C++时出现许多包含错误
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 为什么这个音频包络不能通过开关的情况?
- cmath抛出错误C2062、C2059、C2143和C2447.cmath包含在矢量文件中
- 为什么您需要C++头文件的包含保护
- 无法在UE4中包含BP类到CPP类
- 包含开关的功能在C 中不扩展内联
- 如何使用 boost::p rogram_options 解析本身包含开关的命令行参数
- C++从模板参数类型生成包含开关/映射的函数体