Reputation:
I have a project for which I need to compile C programs. The project is in Java. I have to take the program into a JTextArea,(I am using Swing for GUI) , run it against a testfile and output the results into another JTextArea. But something seems to be wrong in my code.
Process p = new ProcessBuilder("c:\\MinGW\\bin\\cc.exe", "program.c").start();
program.c contains the program that user enter into TextArea, and "c:\MinGW\bin\cc.exe" is my c compiler. I checked that this is not raising any exception. It should create a file named a.exe in my current directory having program.c file, but it is not.What is the proper way to do it?
I saw two other post similar to this, but they also don't provide a simple clean solution for this. Also, I have to run the created executable file after it.
Thanks in advance.
Upvotes: 2
Views: 716
Reputation: 7126
What is the proper way to do it?
One way is to use javax.tools.JavaCompiler
"to invoke Java™ programming language compilers from programs." There's an example here.
Upvotes: 2