从Java程序中调用C编译器 [英] Calling C compiler from java program
问题描述
我有一个项目,我需要编译的C程序。该项目是在Java中。我必须把程序转换成的JTextArea,(我使用的Swing GUI),运行它针对testfile的输出结果到其他的JTextArea。但有些事情似乎是错误的,我code。
进程p =新的ProcessBuilder(C:\\\\ \\\\的MinGW斌\\\\ cc.exe,program.c)。开始();
program.c包含该用户进入到文本区域的程序,C:\\ MinGW的\\ BIN \\ cc.exe是我的C编译器。我查了一下,这是不加任何异常。它应该建立一个在我目前有目录program.c文件A.EXE命名的文件,但它是not.What是做到这一点的正确方法?
我看到了另外两个类似的这个职位,但他们也没有为此提供了一个简单干净的解决方案。
另外,我要运行它后创建可执行文件。
先谢谢了。
什么是做它的正确方法?
块引用>的一种方法是使用
javax.tools.JavaCompiler
从程序调用Java™编程语言编译器。这里这里有一个例子。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.
解决方案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.这篇关于从Java程序中调用C编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!