Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a literal variable reference (${foo}) as program argument in a run configuration

Tags:

eclipse

In Eclipse, when you specify arguments in the run dialog, Eclipse interprets ${foo} as a request to use the Eclipse variable foo. I would like to pass a string to my application that contains ${foo} but Eclipse treats this as an undefined variable and gives me an error.

 -Dfoo "bar" --pattern "regex magic ${foo}"

Eclipse does not accept the single quote (') as a quoting character, instead it becomes part of the input. Does anyone know how I can escape ${foo} in this dialog so it is interpreted as text and not a variable reference?

like image 291
schmmd Avatar asked Jan 26 '11 05:01

schmmd


People also ask

How do I pass program arguments in Intellij?

From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments. Type the arguments in the Program arguments field.


2 Answers

${foo} by itself can be escaped with $"{foo}".

When ${foo} is already part of a doubly-quoted string, as in your question, I'm not sure how or if it can be escaped.

like image 50
Haakon Avatar answered Oct 17 '22 04:10

Haakon


I do not think there is any way to do this in Eclipse.

The offending bit of code is org.eclipse.core.internal.variables.StringSubstitutionEngine#substitute.

This is the bit of code that substitutes the ${foo} with whatever you've defined foo to be. Unfortunately, it can cope with nested and concatenated variables, so if dollar="$" and rest="{foo}" then ${dollar}${rest} gives ${foo} which gets evaluated again.

For info, in the code reportUndefinedVariables is hardcoded as true further up the stack, which is why you're getting the error message. There doesn't seem to be any way of changing it.

like image 39
Matthew Farwell Avatar answered Oct 17 '22 02:10

Matthew Farwell