-2

I want to create a java program which will compile and execute program written in c++. Ijust wanted to know the links or get any idea how will I do this, I want to learn by-self, but not sure from where i should start. I got a link for executing a ".exe" file, which is the part of my program, but how can I compile a C++ program through Java.

I tried to search the related stuff, but was unable to find...suggestions are appreciated...

2 Answers2

0

Here's how you should use Runtime.exec() to execute a C++ compiler. You might also try its more modern cousin, ProcessBuilder:

Java Runtime.getRuntime().exec() alternatives

Community
  • 1
  • 1
YSC
  • 38,212
  • 9
  • 96
  • 149
0

I think you want to run a .exe file through Java.

You should try Runtime.getRuntime().exec(String command, String[] envparam, File dir) with:

  • command is the location of the .exe
  • envparam can be null
  • dir is the directory of your .exe

Example:

Runtime.getRuntime().exec("c:\\program files\\test\\test.exe", null, new File("c:\\program files\\test\\"));
codeaholicguy
  • 1,671
  • 1
  • 11
  • 18