Eclipse & quotes in command line arguments?

I have C ++ code that expects it to look like this:

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

including quotation marks. They can be single or double quotes, but they must be there. In Eclipse, if I configure the command line arguments (Debug configurations / Arguments) and enter the command line option above (minus / path / to / exe), Eclipse eats quotes. Since I run this on Linux, the square brackets give the shell grief, and it never turns it into my code.

If I configure the command line arguments this way:

"it is quoted"

argv [1] is as follows:

it is quoted

i.e. without quotes. If I configure the command line this way:

\ "this is quoted \"

I get:

argv[1]: "this argv[2]: is argv[3]: quoted" 

If I try to put square brackets in it, it returns to the shell mourning pressure, even if I try to avoid them:

 \"\[this is quoted\]\" 

How can I tell Eclipse to accept command line arguments exactly the same as I entered them?

thanks

+6
source share
3 answers

I think I found a solution - at least it worked several times in a row. On the Eclipse Arguments tab, in the Program Settings field, enter a command-line option as follows:

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

It turns into:

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

in the gdb set set command. I end up with single quotes around the square bracket expression, but this works great for my application. I don’t know why this works (I would like me to do this) or why other ways to avoid the text failed.

The order of double and single quotes matters. If you try to put single quotes outside, it will turn into

 set args -p:parameterName=\"[foo,bar]\" 

which fails. Not sure what I would do if double quotes were required.

+2
source

I fixed it, so now there are clear rules for providing arguments. You can read more about this here:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=474648

The basic principles are that Run and Debug should behave the same way, arguments are primarily what the program received, not bash, and the rules for providing arguments should be simple and intuitive. It is impossible to avoid the rules altogether, as when using one line to pass each argument, some special marking is inevitable.

So, the arguments work as follows:

  • Any character following a backslash is literally processed and loses special meaning.

  • Any character after the quote and before the next corresponding quote (or EOF) is processed literally and loses special meaning (both single and double).

  • An empty space is used as the argument separator (except for shielded or inside quotation marks).

The previous behavior was largely undefined, since something like `date` would be subbed using bash, and yet the behavior was not always identical to the behavior of bash. This may ruin some hacker configurations for users, but now rewriting is trivial, and before the correct line needs to be found using trial and error with various combinations of escape quotes, β€œdo I need one, two or four backslashes?”.

+2
source

Have you tried

 "\"\[this is quoted\]\"" 

?

BTW: This is not an eclipse problem, but simply reflects the behavior of the shell.

0
source

All Articles