0

我正在用 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>s,每个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尝试将它们解析为包装器开关的一部分,因为它不知道它们应该在command0or下组合在一起command1

program_options支持吗?如果是这样,怎么做?


例子:

在我工作的地方,有一个惯例是通过像这样“终止”多令牌来做到这一点:

wrapper <snip> --command0 /path0/benchmark0 -switch0 -switch1 -switch2 -command0- 

--command0(在本例中,我以.结尾-command0-。)

我怎么能program_options像这样处理它?

4

1 回答 1

1

我认为最好将command0andcommand1的值作为单个字符串。例如,

wrapper --command0 "/path0/benchmark0 ..." --command1 "/path1/benchmark1 ..."

是的,还有更多工作要做,因为您必须使用wordexp各自的命令字符串(除非您已经将这些字符串直接传递给 shell ;-)),但它更清楚地区分了包装器的内容和被调用的内容命令。

于 2012-04-19T11:59:26.877 回答