I’m writing a simple parser for a single character command syntax. Two of these single character commands are “&” and “%”. However, in my parser code, when I include:
if (cmd.compareTo("&")==0)
{
…
(where cmd is declared as “String cmd;”)
then the compiler seems to screw up somehow and the entire program starts behaving oddly. Take out that line and it’s all fine again. Change that line to something else such as:
if (cmd.compareTo(“D”)==0)
{
…
and everything works as it should. So I’m thinking of three possibilities here.
The parser code is running in response to a cloud function call (i.e. it is exposed by spark.function…) and all web syntaxes make pretty liberal use of “&”, perhaps this has some bearing?
Perhaps ampersand is a disallowed character in the string processing context I am using it? I know some languages and implementations use it as a continuation character across multiple physical lines.
Perhaps there is a bug in the compareTo code, or the way it compiles?
Can anyone shine a light on this for me? It’s not an urgent problem, I CAN (and have) changed the design to use other characters, but it would be nice to understand why this happened.
This is shell (commandline interpretter) getting in your way. Adding & at the end of command instructs shell to run in in background. Either backslash it, or put it in quotes (recommended):