How to call java from C++

前端 未结 4 1921
遇见更好的自我
遇见更好的自我 2020-12-21 17:27

I need to run this line from my c++ program:

java -jar test.jar text1 text2

the java app will give a float value and give it to the c++ program.

How

4条回答
  •  一整个雨季
    2020-12-21 18:14

    When I run the java command directly on my command prompt, it works. but when I run the command from the c++ file, the error says "The system cannot execute the specified program" .

    here's my code, im using ms visual studio 2005 :

    #include "stdafx.h"
    
    #include 
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
        float value;
    
        FILE  *child = _popen("java -jar c:\simmetrics_jar_v1_6_2_d07_02_07.jar text1 ssdyr445", "r");
        if (fscanf(child, "%f", &value) == 1)
             {
                fprintf(stdout,"Got Value from simmetrics: %f\n", value);
         }
        else
             {
                fprintf(stdout,"ERROR\n");
             }
        fclose(child);
    
        return 0;
    }
    

提交回复
热议问题