views:

28

answers:

2

I'm writing a text/code editing program for my own use in Java/Swing, and was wondering how I would go about setting up a built-in C compiler inside it. I would likely use GCC or TCC as the compiler. Anyway, my question is- how would I actually implement the compiler? Would I use a library that gives Java access to command line commands? Are there such libraries and if so, which is the best/easiest to use?

Thanks.

+2  A: 

Accessing command line is the easiest way. Try something like this:

Process myProc = Runtime.getRuntime().exec(command);

Where command is some string you want to pass to the command line.

After that you can redirect output / input of that process to the some java buffers to have the full control.

myProc.getInputStream();
myProc.getOutputStream();
Klark
+2  A: 

Typically IDE/Editor's don't implement the compilers. They will just execute the commands and pass the filename as argument (along with other necessary files). They also pipe/stream the output to a separate window/pane in the editor. So you need to integrate the compiler somehow not implement one. You can execute the commands in java using Runtime class. Start here.

Teja Kantamneni