问题描述
我有一些C ++代码,希望它的命令行看起来像这样:
/ path / to / exe -p:parameterName =[/ path / to / a / file,/ path / to / another / file]
它们可以是单引号或双引号,但它们必须在那里。在Eclipse中,如果我设置了命令行参数(Debug configurations / Arguments)并输入上面的命令行选项(减去/ path / to / exe),Eclipse就会使用引号。因为我在Linux上运行这个方括号给了shell悲伤,甚至从来没有把它放到我的代码中。
如果我设置命令行args :
这是引号
argv [1]看起来像这样:
这是引号
ie没有引号。如果我这样设置命令行:
\这是引用的\
:
argv [1]:this
argv [2]:is
argv [3] :引用
如果我试图把方括号放回去给予shell悲伤,即使我试图逃避他们:
\\ [this is quoted\] \
我如何让Eclipse接受我输入的命令行参数?
感谢
解决方案 - 至少这已经连续工作了几次现在。在Eclipse参数选项卡的程序参数字段中输入命令行参数,如下所示:
-p:parameterName ='[foo,bar] / p>
这会变成:
-p:parameterName ='[foo,bar]'
在gdb的set args命令中。我用单引号围绕方括号表达式,但这对我的应用程序很好。我不知道为什么这个工作(我希望我做),或为什么其他方式的转义文本失败。
double&单引号重要。如果你尝试把单引号放在外面,它变成
设置args -p:parameterName = \[foo,bar] \
失败。不确定如果需要双引号,我该怎么办。
I have some C++ code that expects it's command line to look like this:
/path/to/exe -p:parameterName="[/path/to/a/file,/path/to/another/file]"
including the quotation marks. They can be single or double quotes, but they must be there. In Eclipse if I set up the command line arguments (Debug configurations/Arguments) and enter the command line option above (minus the /path/to/exe) Eclipse eats the quotes. Since I'm running this on Linux the square brackets give the shell grief, and it never even makes it into my code.
If I set up the command line args thus:
"this is quoted"
argv[1] looks like this:
this is quoted
i.e. without the quotes. If I set up the command line thus:
\"this is quoted\"
I get:
argv[1]: "this
argv[2]: is
argv[3]: quoted"
If I try to put the square brackets in it goes back to giving the shell grief, even if I try to escape them:
\"\[this is quoted\]\"
How do I tell Eclipse to take my command line arguments exactly as I've entered them?
Thanks
I think I've found a solution - at least this has worked several times in a row now. In Eclipse's Arguments tab, in the "Program arguments" field enter the command line parameter as follows:
-p:parameterName="'[foo,bar]'"
This turns into:
-p:parameterName='[foo,bar]'
in gdb's "set args" command. I wind up with single quotes around the square-bracket expression but that's fine for my application. I don't know why this works (I wish I did) or why the other ways of escaping text failed.
The order of the double & single quotes matters. If you try putting the single quotes on the outside it gets turned into
set args -p:parameterName=\"[foo,bar]\"
which fails. Not sure what I'd do if double quotes were required.
这篇关于Eclipse&命令行参数中的引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!