Help !!!
I am trying to invoke a command from my java program running under Redhat Linux using Java 1.6. The command i'm trying to execute is actually a shell script that executes a query on a remote system (GNATS - a bug tracking tool).
I need to execute the following command through my java program.
query-pr --host mygnatsdb.dom.net --port 1568 --expr '(last-modified > "2009-06-15")'
When I run this command directly at the command prompt, it executes fine.
However, if I run it from java, the tool complains that the query expression is Invalid. Somehow its not able to parse the expression passed in the last argument.
1] Escaping the quotes does not work. Same results.
2] I tried double escaping them (--expr '(last-modified > \\\"2009-06-15\\\")') thinking that java is doing some sort of parsing again before actually invoking my command, but that ended in the same result.
3] I cannot use single quotes as they are being used at the begingin to mark the start and end of the query expression, and switching between them is not allowed.
4] I tried using the exec(String[] cmdarray) method, however I'm not sure if I used it correctly, because it did not work. Tried several variations.
String cmdarr[] = {"query-pr", "--host", "spyro.juniper.net", "--port", "1528", --expr '(last-modified > \"2009-06-15\")};
Runtime.exec(cmdarray).
Now I have reached my wits end
and can't seem to make any progress. Please help !!!
Bhay.