如何从C ++调用java [英] How to call java from C++
本文介绍了如何从C ++调用java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从我的c ++程序运行这行:
I need to run this line from my c++ program:
java -jar test.jar text1 text2
java -jar test.jar text1 text2
java应用程序将给出一个浮点值并将其提供给c ++程序。
the java app will give a float value and give it to the c++ program.
我如何做到这一点?我从来没有调用一个java东西从我的视觉工作室C ++文件。
How can I do this? I never call a java stuff before from my ms visual studio C++ file.
推荐答案
当我直接在命令提示符下运行java命令时,它工作。但是当我从c ++文件运行命令时,错误说系统不能执行指定的程序。
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" .
这里是我的代码,im使用ms visual studio 2005:
here's my code, im using ms visual studio 2005 :
#include "stdafx.h"
#include <conio.h>
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;
}
这篇关于如何从C ++调用java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文