#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    11
    Rep Power
    0

    Question error specifying path for CreateProcess


    Hi Everyone,

    Can someone please help me with this problem, Thanks ahead of time:
    I am trying to use CreateProcess() to launch a java
    executable and then wait for it to terminate. This is what
    my code looks like:

    NIpath = "java -
    classpath .;ni.jar;lib\\snmp4_13.jar;lib\\comm.jar;lib\\tab
    lelayout.jar;lib\\jaxb\\jax-qname.jar;lib\\jaxb\\jaxb-
    api.jar;lib\\jaxb\\jaxb-libs.jar;lib\\jaxb\\jaxb-
    ri.jar;lib\\jaxb\\jaxb-xjc.jar;lib\\jaxb\\namespace.jar
    com.ni.NI";

    createProcessStatus = CreateProcess(NULL, NIpath, NULL,
    NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

    (There is a space between the long string after -classpath and "com.ni.NI")
    The problem is with NIpath. CreateProcess executes without
    error if the com.ni.NI executable is in
    the same directory as my program's executable, however as
    soon as i place in some other directory ( i.e. NetInv/
    with NIpath = "java -
    classpath .;...lib\\jaxb\\namespace.jar NetInv.com.ni.NI" )I get an error.
    I think it has something to with the fact that part of
    the path I specified is compressed in a .jar file
    (everything except for NetInv/ is in .jar file). Does
    anybody have a clue as to what's going on?

    btw, error = "Exception in thread "main"
    java.lang.NoClassDefFoundError:
    NetInv/com/ni/NI "

    also when executable is in the same folder as my program's
    executable, it only works properly when I physically
    double click on the executable that is generated, if i run
    my executable from visual studio i get the same error. Why
    does this happen, does it run the executable from some
    other location??
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,595
    Rep Power
    4207
    I notice that you have the first argument of CreateProcess() as NULL. Have you tried calling CreateProcess like this instead:

    createProcessStatus = CreateProcess("java", "-classpath .;...restofstuff...", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi);

    You may need to set the first argument to "/path/to/java" instead of plain "java". Also, the lpCurrentDirectory parameter might need to be set. See http://msdn.microsoft.com/library/de...ateprocess.asp for more info about this.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    11
    Rep Power
    0

    Question thank you, but it didnt work, any other ideas?


    Thanks for your advice but it didnt work, I still think the problem has something to do with .jar compressed files. Even if I am right though, I do not know how to get around the problem. I tried several things:

    char * NIpath = "java
    -classpath
    .;ni.jar;lib\\snmp4_13.jar;lib\\comm.jar;lib\\tablelayout.jar;lib\\jaxb\\jax-qname.jar;lib\\jaxb\\jaxb-api.jar;lib\\jaxb\\jaxb-libs.jar;lib\\jaxb\\jaxb-ri.jar;lib\\jaxb\\jaxb-xjc.jar;lib\\jaxb\\namespace.jar
    com.ni.NetInventory";

    char * NIpath2 = "java
    -classpath
    .;ni.jar;lib\\snmp4_13.jar;lib\\comm.jar;lib\\tablelayout.jar;lib\\jaxb\\jax-qname.jar;lib\\jaxb\\jaxb-api.jar;lib\\jaxb\\jaxb-libs.jar;lib\\jaxb\\jaxb-ri.jar;lib\\jaxb\\jaxb-xjc.jar;lib\\jaxb\\namespace.jar
    NI.com.ni.NetInv";

    char * NIcommand = "C:\\Program Files\\Java\\j2re1.4.1_02\\java
    -classpath
    .;ni.jar;lib\\snmp4_13.jar;lib\\comm.jar;lib\\tablelayout.jar;lib\\jaxb\\jax-qname.jar;lib\\jaxb\\jaxb-api.jar;lib\\jaxb\\jaxb-libs.jar;lib\\jaxb\\jaxb-ri.jar;lib\\jaxb\\jaxb-xjc.jar;lib\\jaxb\\namespace.jar";

    char * NIcompath = "NI.com.ni.NetInven";

    char * curWorkingDir = "C:\\RelCalc\\RelCalc\\Debug";

    //attempt 1
    createProcessStatus = CreateProcess(( "java", "-class path ..restof of stuff", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, curWorkingDir, &si, &pi); //error code 2

    //attempt 2
    createProcessStatus = CreateProcess(( "C:\\Program Files\\..\\bin\\java", "-classpath ..restofstuff", NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, curWorkingDir, &si, &pi);
    //error code 2

    //attempt 3
    createProcessStatus = CreateProcess(( NIcompath, NIcommand, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, curWorkingDir, &si, &pi);

    //attempt 4
    createProcessStatus = CreateProcess(( NIcommand, NIcompath, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, curWorkingDir, &si, &pi);

    //still the only thing that work is
    createProcessStatus = CreateProcess(( NULL, NIpath, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, curWorkingDir, &si, &pi);//when i double click on teh .exe generated, not when I run it from visual studio .. what is going on!?

    Any additional advice will be greatly appreciated.
    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo