This discussion is archived
6 Replies Latest reply: Oct 5, 2011 5:18 AM by 802889 RSS

Multiple Strings as Commandline argument

875447 Newbie
Currently Being Moderated
Hello people,

Everything is working properly, but I have a problem starting a method via command line argument.
int main(int argc, char** argv)
{
     char  *p2Jar =     "-Djava.class.path=C:\\path\\myJAR.jar";
     char  *p2Lib =     "";

     JNI_IF JNIInterfaceObj(p2Jar, p2Lib);
     JNIInterfaceObj.setClassName("package/depth/MyClass");;
     JNIInterfaceObj.setMethodName("main");
     JNIInterfaceObj.getVM()->DestroyJavaVM();
     return 0;
}

void JNI_IF::setMethodName(char* methodName)
{
     mid =     env->GetStaticMethodID(cls, methodName, "([Ljava/lang/String;)V");

     const char * t_argv = "-m tomtom_utrecht_2008_04.db3 -i \"L;ID;0,0,15280001229524,15280001349498,-15280001349500\" -if LOCATION_STRING -of BINARY64";
     jobjectArray applicationArgs = env->NewObjectArray(1, env->FindClass("java/lang/String"), NULL);
     jstring applicationArg0 = env->NewStringUTF(t_argv);
     env->SetObjectArrayElement(applicationArgs, 0, applicationArg0);
     if (mid != NULL) env->CallStaticVoidMethod(cls, mid, applicationArgs);
     else printf("Method %s corrupted!\n", methodName);
}
the command line argument is not accepted. the real string i have to deliver to the function is:
-m tomtom_utrecht_2008_04.db3 -i "L;ID;0,0,15280001229524,15280001349498,-15280001349500" -if LOCATION_STRING -of BINARY64

As you can see, a *"* is used in that string. I quoted it with the *\*

Is that wrong quoting?

Does anybody have any hints for me?

Thank you!

Cheers huck

Edited by: huckleberry on 08.09.2011 00:16

Edited by: EJP on 8/09/2011 18:35: code tags
  • 1. Re: Multiple Strings as Commandline argument
    875447 Newbie
    Currently Being Moderated
    The message:

    *Error: "-m tomtom_utrecht_2008_04.db3 -i "L;ID;0,0,15280001229524,15280001349498
    ,-15280001349500" -if LOCATION_STRING -of BINARY64" ist keine g´┐¢ltige Option*

    ".. is no valid option"
  • 2. Re: Multiple Strings as Commandline argument
    EJP Guru
    Currently Being Moderated
    First you would have to tell us what JNI_IF does.

    It doesn't appear to have improved much from JNI Version Wrong? Error Code = JNI_EVERSION.
  • 3. Re: Multiple Strings as Commandline argument
    875447 Newbie
    Currently Being Moderated
    JNI_IF is a kind of a handler, which triggers a method from a jar file, which I need in my C++ project. That myJAR.jar which demands the mentioned string as parameter.

    With that earlier code you've mentioned in the previous post, there was the "70" as inputparameter and that worked properly.

    The thing what have been changed is, I have a " in my string itself.
  • 4. Re: Multiple Strings as Commandline argument
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    huckleberry wrote:
    JNI_IF is a kind of a handler, which triggers a method from a jar file, which I need in my C++ project. That myJAR.jar which demands the mentioned string as parameter.

    With that earlier code you've mentioned in the previous post, there was the "70" as inputparameter and that worked properly.

    The thing what have been changed is, I have a " in my string itself.
    Nope.

    You have CODE which has nothing to do with java nor jni to which WE do not have access.

    Let us call that code X.

    X is doing something. WE don't know what. And it isn't working. Since we don't have X we can't possibly tell you what is wrong.

    One thing I can tell you - you are embedding double quotes in your string. Since that presumably isn't working it is pretty certain that that by itself is not going to lead to a solution. However to verify you should print your arg string before using it - JUST before you use it. Then you can verify the form.


    Other than that I can provide some guesses.

    1. X is calling an external executable. X does not have a way to correctly parametrize arguments. Or it does and you are not using it. If the first then you are probably out of luck. If the second then you should figure it out.

    2. X is doing some sort of pseudo argument passing mechanism. Either you do not understand how it works or the code is doing it wrong. Solution to the first is to figure out the correct way. Second best you can do is try some other way of doing it.

    3. You are attempting to parametrize or escape something. The question is what. Normally the idiom (quotes) would only be needed with spaces in the parameter. Presumably you tried it without quotes. There might be a way to escape the '-' (only thing I can see that would need double quotes). You MIGHT do that with \\- (two back slashes - not one.) But there might be some other way as well.
  • 5. Re: Multiple Strings as Commandline argument
    875447 Newbie
    Currently Being Moderated
    JNI_IF (from C++ Side) invokes my Java-Project (an executable jar) which returns a String e.g.: "myresult"

    (C++) (Java)
    . JNI_IF ------------> myJAR.jar (trigger public String getResult(){return "myresult"} )
    . <--- "myresult" <---+ return "myresult"

    I just wanted to access that return String.

    Anyway, I already solved that via Sockets. Since I have much more result Strings as expected, my JNI_IF communicates with my java executable via Sockets.
    Sorry for any inconvenience.

    Cheers Huck

    Edited by: huckleberry on 04.10.2011 04:36

    Edited by: huckleberry on 04.10.2011 04:36
  • 6. Re: Multiple Strings as Commandline argument
    802889 Explorer
    Currently Being Moderated
    huckleberry wrote:
    Hello people,

    Everything is working properly, but I have a problem starting a method via command line argument.
         const char * t_argv = "-m tomtom_utrecht_2008_04.db3 -i \"L;ID;0,0,15280001229524,15280001349498,-15280001349500\" -if LOCATION_STRING -of BINARY64";
         jobjectArray applicationArgs = env->NewObjectArray(1, env->FindClass("java/lang/String"), NULL);
         jstring applicationArg0 = env->NewStringUTF(t_argv);
         env->SetObjectArrayElement(applicationArgs, 0, applicationArg0);
    To me this suggests that applicationArgs needs to have the same number of elements as there are commandline options (so 8 in total), not just one big element containing all arguments in one string, and then you need to add every individual commandline argument as a separate element.

    Edited by: TheAvalanche on 5-okt-2011 5:18

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points