Eclipse&引用命令行参数? [英] Eclipse & quotes in command line arguments?

查看:86
本文介绍了Eclipse&引用命令行参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些C ++代码,期望它的命令行如下所示:



/ path / to / exe -p:parameterName =[/ path / to / a / file,/ path / to / another / file]



包括引号。它们可以是单引号或双引号,但它们必须在那里。在Eclipse中,如果我设置了命令行参数(Debug configured / Arguments)并输入上面的命令行选项(减去/ path / to / exe),Eclipse会使用引号。因为我在Linux上运行这个方括号给了shell的悲伤,甚至从来没有把它放入我的代码。



如果我设置了命令行args :



这是引用



argv [1]看起来像这样:



这是引用



ie没有引号。如果我设置了命令行:



\这是quoted\



我得到:

$ b

  argv [1]:这个
argv [2]:是
argv [3] :引用

如果我尝试把方括号放回来给壳的悲伤,即使我试图逃避他们:

  \\ [这是引用的\] \
/ / code>

如何让Eclipse直接按照我输入的命令行参数?



谢谢

解决方案

我认为我找到了解决方案 - 至少这已经连续工作了好几次了。在Eclipse的Arguments选项卡中,在程序参数字段中输入命令行参数,如下所示:

  -p:parameterName = '[foo,bar]'

这变成:

  -p:parameterName ='[foo,bar]'


$ gdb的set args命令中的b $ b

。我用单引号围绕方括号表达式结束,但对我的应用程序来说很好。我不知道为什么这个工作(我希望我这样做)或为什么其他方式逃避文本失败。



双重&单引号很重要。如果你尝试将单引号放在外面,它会变成

  set 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&引用命令行参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆