I am trying to call a C++ program from java and my C++ program as follows:
// A hello world program in C++
// hello.cpp
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
What I did was I am using minGW compiler
for compiling C++ program to hello.exe and when I working it, it is working:
C:\Users\admin\Desktop>g++ -o hello hello.cpp
C:\Users\admin\Desktop>hello.exe
Hello World!
I have created a java program in such a way that it should call the C++compiled program(hello.exe), but my java program is note calling the exe, my program as follows:
//Hello.java
public class Hello {
public static void main(String []args) {
String filePath = "hello.exe";
try {
Process p = Runtime.getRuntime().exec(filePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Check the output of java program:
C:\Users\admin\Desktop>javac Hello.java
C:\Users\admin\Desktop>java Hello
C:\Users\admin\Desktop>
Why it is not working, Please help me?